Introduction: Game Show Controller 1.0

I teach at the University of Missouri, and I wanted a method to add some "Gamification" to my exam review exercises. There is a lot of evidence and research that using a game in class can help with student learning (it activates different pathways in the brain (social, reward, motor-sensory, etc.). For a quick summary, check out The Five Benefits of Adding Gamification to Classrooms. Gamification:

  • Boosts enthusiasm toward math
  • Lessens disruptive behavior
  • Increases cognitive growth
  • Incorporates mature make-believe which encourages growth and development, and
  • Improves attention span through game-centric learning.

So when I saw a blog post on the Adafruit site about using and modifying a set of cheap game show controllers ( Wireless Game Show Poppers for the Classroom! Pro Trinket + Hacked Duo Pop Game = Game Show Fun!), I thought this might be a great solution. However, as I played with this solution more, I decided that I needed something that would be free standing and not require a particular piece of software or computer connection to work. At that time, I had also started playing with the 16x8 1.2" LED Matrix (https://www.adafruit.com/products/2039) and loved the display and scrolling text that you could make. So, I set off to come up with a stand-alone Game Show Controller, that would use the POP IR transmitters, with four 16X8 LED matrixes that would display scores, status, etc.

Step 1: Assemble the Matrix Backpacks and Set the Matrix IDs

Picture of Assemble the Matrix Backpacks and Set the Matrix IDs

This is a simple step, just solder the matrixes onto their backpacks, and then on three of the backpacks, you need to solder a little blob of solder across the gold pads to set the I2C IDs. For mine, I set the IDs as follows:

  • Red Matrix: No connection, which leaves the matrix at the default ID of 0x70.
  • Blue Matrix: Connect A1, which sets the matrix to the ID of 0x72.
  • Green Matrix: Connect A2, which sets the matrix to the ID of 0x74.
  • Yellow Matrix: Connect A0, which sets the matrix to the ID of 0x71.

It doesn't matter what ID you set, as you can change this in the programming. You just need to have a unique ID for each matrix.

Step 2: Wiring and Mounting the Base

Picture of Wiring and Mounting the Base

Here are the parts I ended up using for this project.

I didn't want to permanently mount the matrix to the front of the controller, as they are more expensive and I wanted to be able to unplug them and use them for other purposes. That is why I used the IC sockets to hold the matrixes. Once you solder the headers onto the matrixes, you can just plug them into the front of the controller when you want to use it. Since the ID of each matrix is determined by jumpering two pads on the back of the matrix, the matrixes can be inserted in any order. I also made it easy to remove the buzzer and the IR receiver.

Obviously, you could do this in different form factors.

Step 3: Changes to Code for Displays, Etc.

Picture of Changes to Code for Displays, Etc.

I used the code from the original project to add in the matrixes, using the code and libraries posted on the Adafruit site for displaying text on the matrixes. Below is the code that I finally ended up with. It is possible that the transmitter in the controllers that you use, will transmit a different code (or if you are using with different controllers). If so, Adafruit has a nice " Using an IR Sensor" tutorial that you can use to figure out the matching IR codes.

#include <wire.h><br>#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"</wire.h></p><p>#define IRpin_PIN      PINC
#define IRpin          PINC0
#define MAXPULSE 1000
#define RESOLUTION 20 
#define FUZZINESS 45
 
// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2];  // pair is high and low pulse 
uint8_t currentpulse = 0; // index for pulses we're storing
 
//speaker 
int speakerPin = 12;</p><p>//for matrix
Adafruit_8x16matrix Redmatrix = Adafruit_8x16matrix();
Adafruit_8x16matrix Bluematrix = Adafruit_8x16matrix();
Adafruit_8x16matrix Greenmatrix = Adafruit_8x16matrix();
Adafruit_8x16matrix Yellowmatrix = Adafruit_8x16matrix();
 
// Red Code
int DUOPOPsignalRed[] = { // ON, OFF (in 10's of microseconds) 
140, 50, 
100, 50, 
100, 100, 
50, 50, 
100, 50, 
100, 50, 
100, 100,  
50, 50,  
100, 50,  
100};
 
// Blue Code
 
int DUOPOPsignalBlue[] = { // ON, OFF (in 10's of microseconds) 
140, 50, 
100, 50, 
100, 50, 
100, 100, 
50, 50, 
100, 50, 
100, 50,  
100, 100,  
50, 50,  
100};
 
// Yellow Code
 
int DUOPOPsignalYellow[] = { // ON, OFF (in 10's of microseconds) 
140, 
100, 50, 
50, 100, 
100, 50, 
50, 100, 
100, 50, 
50, 100, 
100, 50, 
50, 100, 
50, 100};
 
// Green Code
 
int DUOPOPsignalGreen[] = { // ON, OFF (in 10's of microseconds) 
140, 
50, 100, 
100, 50, 
50, 100,
100, 50, 
50, 100, 
100, 50, 
50, 100, 
100, 50, 
50, 100};</p><p>int buttonCorrect = 10; //whoever buzzed in, let's add 1 point !
int buttonCorrectState;
int lastbuttonCorrectState;</p><p>int buttonWrong = 9; //whoever buzzed in, let's dock them 2 points !
int buttonWrongState;
int lastbuttonWrongState;</p><p>int buttonReset =8 ; //There was an error or for some reason we don't want to count this rount
int buttonResetState;
int lastbuttonResetState;</p><p>int BuzzedIn = 0;</p><p>int RedNumberCorrect =0;
int GreenNumberCorrect =0;
int BlueNumberCorrect =0;
int YellowNumberCorrect =0;
int ReadytoPlay =0;
int numTones = 10;
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};
//            mid C  C#   D    D#   E    F    F#   G    G#   A</p><p>static const uint8_t PROGMEM
  smile_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10100101,
    B10011001,
    B01000010,
    B00111100 },
  neutral_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10111101,
    B10000001,
    B01000010,
    B00111100 },
  frown_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10011001,
    B10100101,
    B01000010,
    B00111100 };</p><p>void setup(void) {
  Serial.begin(9600);
  pinMode(buttonCorrect, INPUT_PULLUP);  
  pinMode(buttonWrong, INPUT_PULLUP); 
  pinMode(buttonReset, INPUT_PULLUP);   
  pinMode(IRpin, INPUT); 
  
 //SETUP THE DISPLAYS. 
    Redmatrix.begin(0x70);  // pass  the address
    Bluematrix.begin(0x72);  // pass  the address
    Greenmatrix.begin(0x74);  // pass  the address
    Yellowmatrix.begin(0x71);  // pass  the address
    Yellowmatrix.setTextSize (0);
    Yellowmatrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Yellowmatrix.setTextColor(LED_ON);
    Yellowmatrix.setRotation(1);
    Bluematrix.setTextSize(0);
    Bluematrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Bluematrix.setTextColor(LED_ON);
    Bluematrix.setRotation(1);
    Redmatrix.setTextSize(0);
    Redmatrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Redmatrix.setTextColor(LED_ON);
    Redmatrix.setRotation(1);
    Greenmatrix.setTextSize(0);
    Greenmatrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Greenmatrix.setTextColor(LED_ON);
    Greenmatrix.setRotation(1);
    DisplayScore();
}
 
 
void loop(void) {</p><p>  ReadbuttonReset ();
  ReadbuttonCorrect ();
  ReadbuttonWrong ();
  int numberpulses;
  if (ReadytoPlay ==1) {
    numberpulses = listenForIR();
    }</p><p>  if (numberpulses == 10)
  {  
  if (IRcompare(numberpulses, DUOPOPsignalRed)) {
    Serial.println("RED Buzzed In");
    ReadytoPlay =0;
    BuzzedIn =1; //red
    tone(speakerPin, 311);
    Redmatrix.clear();
    Redmatrix.setCursor(2,1);
    Redmatrix.print("**");
    Redmatrix.writeDisplay();
    delay(50);
    noTone(speakerPin); 
  }
  if (IRcompare(numberpulses, DUOPOPsignalBlue)) {
     Serial.println("BLUE Buzzed In");
     ReadytoPlay =0;
     BuzzedIn =2; //blue
     tone(speakerPin, 311);
     Bluematrix.clear();
     Bluematrix.setCursor(3,1);
     Bluematrix.print("**");
     Bluematrix.writeDisplay();
     delay(50);
     noTone(speakerPin); 
  }
    if (IRcompare(numberpulses, DUOPOPsignalYellow)) {
    Serial.println("Yellow Buzzed In");
    ReadytoPlay =0;
    BuzzedIn =3; //Yellow
    tone(speakerPin, 311);
     Yellowmatrix.clear();
    Yellowmatrix.setCursor(2,1);
    Yellowmatrix.print("**");
    Yellowmatrix.writeDisplay();
    delay(50);
     noTone(speakerPin); 
  }
   if (IRcompare(numberpulses, DUOPOPsignalGreen)) {
    Serial.println("Green Buzzed In");
    ReadytoPlay =0;
    BuzzedIn =4; //Green
    tone(speakerPin, 311);
     Greenmatrix.clear();
    Greenmatrix.setCursor(2,1);
    Greenmatrix.print("**");
    Greenmatrix.writeDisplay();
    delay(50);
    noTone(speakerPin); 
  }
  }
  
}
 
void PlayCorrect ()
{
  for (int i = 0; i < numTones; i++)
  {
    tone(speakerPin, tones[i]);
    delay(70);
  }
  noTone(speakerPin);
}
    
void PlayWrong ()
{
  for (int i = 11; i > 0; i--)
  {
    tone(speakerPin, tones[i]);
    delay(70);
  }
  noTone(speakerPin);
}
 
 
void BuzzersReady ()
{
  Serial.println("Get your buzzers ready");
   for (int8_t x=7; x>=-46; x--) {
    Redmatrix.clear();
    Redmatrix.setCursor(x,0);
    Redmatrix.print("Get Ready");
    Redmatrix.writeDisplay();
     Bluematrix.clear();
    Bluematrix.setCursor(x,0);
    Bluematrix.print("Get Ready");
    Bluematrix.writeDisplay();
     Greenmatrix.clear();
    Greenmatrix.setCursor(x,0);
    Greenmatrix.print("Get Ready");
    Greenmatrix.writeDisplay();
     Yellowmatrix.clear();
    Yellowmatrix.setCursor(x,0);
    Yellowmatrix.print("Get Ready");
    Yellowmatrix.writeDisplay();
    delay(40);
    
  }
  BuzzedIn =0;
  DisplayScore ();
  ReadytoPlay =1;//system will be unresponsive until this comes back to 0
}
 
void ReadbuttonReset()
{
  //read the pushbutton input pin:
  buttonResetState = digitalRead(buttonReset);
  // compare the buttonState to its previous state for on button
  if (buttonResetState != lastbuttonResetState) {
    if (buttonResetState == LOW) {
      // if the current state is LOW then the button wend from off to on and the button was pressed:
      BuzzersReady();
      } 
      lastbuttonResetState = buttonResetState;  
  }
}</p><p>void ReadbuttonCorrect()
{
  // read the pushbutton input pin:
  buttonCorrectState = digitalRead(buttonCorrect);
  // compare the buttonState to its previous state for on button
  if (buttonCorrectState != lastbuttonCorrectState) {
   if (buttonCorrectState == LOW) {
   //whoever has buzzed in should get some points. 
   PlayCorrect ();
    switch (BuzzedIn)
    {
    case 1: //red
     RedNumberCorrect = RedNumberCorrect+1 ;
      break;
    case 2: //blue
    BlueNumberCorrect = BlueNumberCorrect+1 ;
      break;
    case 3: //yellow
    YellowNumberCorrect = YellowNumberCorrect+1 ;
      break;
    case 4: //green
    GreenNumberCorrect = GreenNumberCorrect+1 ;
      break;
    }
    BuzzersReady ();
    
  }
  }
      lastbuttonCorrectState = buttonCorrectState;
}</p><p>void ReadbuttonWrong()
{
  // read the pushbutton input pin:
  buttonWrongState = digitalRead(buttonWrong);
  // compare the buttonState to its previous state for on button
  if (buttonWrongState != lastbuttonWrongState) {
   if (buttonWrongState == LOW) {
      // if the current state is LOW then the button wend from off to on and the button was pressed:
      PlayWrong ();
    switch (BuzzedIn)
    {
    case 1: //red
     RedNumberCorrect = RedNumberCorrect-2;
      break;
    case 2: //blue
    BlueNumberCorrect = BlueNumberCorrect-2;
      break;
    case 3: //yellow
    YellowNumberCorrect = YellowNumberCorrect-2 ;
      break;
    case 4: //green
    GreenNumberCorrect = GreenNumberCorrect-2 ;
      break;
    }
    BuzzersReady ();
    
  }
  }
      lastbuttonWrongState = buttonWrongState;
}</p><p>void DisplayScore()
{
  Bluematrix.clear();
  Redmatrix.clear();
  Greenmatrix.clear();
  Yellowmatrix.clear();
  Serial.println(" ");
  Serial.println("Score so far");
  Serial.print("Red Team:" ); 
  Serial.println(RedNumberCorrect); 
  Serial.print("Blue Team:" ); 
  Serial.println(BlueNumberCorrect); 
  Serial.print("Yellow Team:" ); 
  Serial.println(YellowNumberCorrect); 
  Serial.print("Green Team:" ); 
  Serial.println(GreenNumberCorrect); 
  </p><p>    if (RedNumberCorrect <= 9 && RedNumberCorrect >=0)
    {
      Redmatrix.setCursor(11,1);
    }
   if (RedNumberCorrect <0 && RedNumberCorrect >= -9)
     {
      Redmatrix.setCursor(5,1); 
     }
     
   if  (RedNumberCorrect >= 10)
     {
      Redmatrix.setCursor(5,1); 
     }
   if  (RedNumberCorrect <= -10)
     {
      Redmatrix.setCursor(-1,1); 
     }
 
    
  Redmatrix.print(RedNumberCorrect);
  Redmatrix.writeDisplay();
  
      if (BlueNumberCorrect <= 9 && BlueNumberCorrect >=0)
    {
      Bluematrix.setCursor(11,1);
    }
   if (BlueNumberCorrect <0 && BlueNumberCorrect >= -9)
     {
      Bluematrix.setCursor(5,1); 
     }
     
   if  (BlueNumberCorrect >= 10)
     {
      Bluematrix.setCursor(5,1); 
     }
   if  (BlueNumberCorrect <= -10)
     {
      Bluematrix.setCursor(-1,1); 
     }
  
  
  Bluematrix.print(BlueNumberCorrect);
  Bluematrix.writeDisplay();
  
  
       if (YellowNumberCorrect <= 9 && YellowNumberCorrect >=0)
    {
      Yellowmatrix.setCursor(11,1);
    }
   if (YellowNumberCorrect <0 && YellowNumberCorrect >= -9)
     {
      Yellowmatrix.setCursor(5,1); 
     }
     
   if  (YellowNumberCorrect >= 10)
     {
      Yellowmatrix.setCursor(5,1); 
     }
   if  (YellowNumberCorrect <= -10)
     {
      Yellowmatrix.setCursor(-1,1); 
     } 
  
  
  
  
 
  Yellowmatrix.print(YellowNumberCorrect);
  Yellowmatrix.writeDisplay();
 
 
 
        if (GreenNumberCorrect <= 9 && GreenNumberCorrect >=0)
    {
      Greenmatrix.setCursor(11,1);
    }
   if (GreenNumberCorrect <0 && GreenNumberCorrect >= -9)
     {
      Greenmatrix.setCursor(5,1); 
     }
     
   if  (GreenNumberCorrect >= 10)
     {
      Greenmatrix.setCursor(5,1); 
     }
   if  (GreenNumberCorrect <= -10)
     {
      Greenmatrix.setCursor(-1,1); 
     } 
 
 
  Greenmatrix.print(GreenNumberCorrect);
  Greenmatrix.writeDisplay();
  
}</p><p>int listenForIR(void) {
  currentpulse = 0;
 
  while (1) {
    uint16_t highpulse, lowpulse;  // temporary storage timing
    highpulse = lowpulse = 0; // start out with no pulse length
 
//  while (digitalRead(IRpin)) { // this is too slow!
   // while (IRpin_PIN & (1 << IRpin)) {
     while (IRpin_PIN & _BV(IRpin)) {
       // pin is still HIGH
 
       // count off another few microseconds
       highpulse++;
       delayMicroseconds(RESOLUTION);
 
       // If the pulse is too long, we 'timed out' - either nothing
       // was received or the code is finished, so print what
       // we've grabbed so far, and then reset
       if (((highpulse >= MAXPULSE) && (currentpulse != 0)) || (currentpulse == 10)) {
         return currentpulse;
       }
    }
    // we didn't time out so lets stash the reading
    pulses[currentpulse][0] = highpulse;
 
    // same as above
    while (! (IRpin_PIN & _BV(IRpin))) {
       // pin is still LOW
       lowpulse++;
       delayMicroseconds(RESOLUTION);
       if (((lowpulse >= MAXPULSE)  && (currentpulse != 0)) || (currentpulse == 10)) {
         return currentpulse;
       }
    }
    pulses[currentpulse][1] = lowpulse;
 
    // we read one high-low pulse successfully, continue!
    currentpulse++;
  }
}
 
 
boolean IRcompare(int numpulses, int Signal[]) {
 
  for (int i=0; i< numpulses-1; i++) {
    int oncode = pulses[i][1] * RESOLUTION / 10;
    int offcode = pulses[i+1][0] * RESOLUTION / 10;
 
    
 //   Serial.print(oncode); // the ON signal we heard
 //   Serial.print(" - ");
 //   Serial.print(Signal[i*2 + 0]); // the ON signal we want 
    
 
    // check to make sure the error is less than FUZZINESS percent
    if ( abs(oncode - Signal[i*2 + 0]) <= (Signal[i*2 + 0] * FUZZINESS / 100)) {
  //    Serial.print(" (ok)");
    
      
    } else {
  //    Serial.print(" (x)");
      // we didn't match perfectly, return a false match
      return false;
    }
 
    
 //   Serial.print("  \t"); // tab
 //   Serial.print(offcode); // the OFF signal we heard
 //   Serial.print(" - ");
 //   Serial.print(Signal[i*2 + 1]); // the OFF signal we want 
    
 
    if ( abs(offcode - Signal[i*2 + 1]) <= (Signal[i*2 + 1] * FUZZINESS / 100)) {
  //    Serial.print(" (ok)");
    } else {
  //    Serial.print(" (x)");
      // we didn't match perfectly, return a false match
      return false;
    }
 
   // Serial.println();
  }
  // Everything matched!
  return true;
}

Step 4: Go Crazy and Build a Monster Version (NOT RECOMMENDED)

So, there were some problems with this controller. First, is that in rooms with fluorescent lights, the IR controllers had to be withing 10 feet of the receiver. (The lights flicker and interfere with the reception). So I went all mad scientist and created a wired version of the controller. To be frank, I went a bit overboard. It works fine but is not easy to maintain, etc. I am posting the code below for any other mad scientists out there who want to try something similar, but I'd not recommend this.



#include 
#include 
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"


//for matrix
Adafruit_8x16matrix Redmatrix = Adafruit_8x16matrix();
Adafruit_8x16matrix Bluematrix = Adafruit_8x16matrix();
Adafruit_8x16matrix Greenmatrix = Adafruit_8x16matrix();
Adafruit_8x16matrix Yellowmatrix = Adafruit_8x16matrix();

Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, 7, NEO_GRB + NEO_KHZ800);


const int buttonRED = 10;
const int buttonBLUE = 11;
const int buttonGREEN = 9;
const int buttonYELLOW =8;

const int Blue_Light = A1;
const int Red_Light = A2;    
const int Green_Light = A4;
const int Yellow_Light = A3;

int  buttonREDState;
int  buttonBLUEState;
int  buttonGREENState;
int  buttonYELLOWState; 

int lastbuttonREDState;
int lastbuttonBLUEState;
int lastbuttonGREENState;
int lastbuttonYELLOWState;

int BuzzedIn =0; //this will track who buzzed in

int RedNumberCorrect =0;
int GreenNumberCorrect =0;
int BlueNumberCorrect =0;
int YellowNumberCorrect =0;

bool ReadytoPlay = 0; //if this is 1 then we will look at buzzer. otherwise we will not

void setup(void) {
	

	pinMode(buttonRED, INPUT);  
	digitalWrite(buttonRED, HIGH);  
	pinMode(buttonBLUE, INPUT);  
	digitalWrite(buttonBLUE, HIGH);
	pinMode(buttonGREEN, INPUT);  
	digitalWrite(buttonGREEN, HIGH);
	pinMode(buttonYELLOW, INPUT);  
	digitalWrite(buttonYELLOW, HIGH);

	pinMode(Red_Light, OUTPUT);
	pinMode(Blue_Light, OUTPUT);
	pinMode(Green_Light, OUTPUT);
	pinMode(Yellow_Light, OUTPUT);	
	
	pinMode (A0, INPUT_PULLUP);
	
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  
  Serial.begin(9600);
 
    
  //get the display's setup. 
    Redmatrix.begin(0x70);  // pass  the address
    Bluematrix.begin(0x71);  // pass  the address
    Greenmatrix.begin(0x72);  // pass  the address
    Yellowmatrix.begin(0x74);  // pass  the address
    Yellowmatrix.setTextSize (0);
    Yellowmatrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Yellowmatrix.setTextColor(LED_ON);
    Yellowmatrix.setRotation(1);
    Bluematrix.setTextSize(0);
    Bluematrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Bluematrix.setTextColor(LED_ON);
    Bluematrix.setRotation(1);
    Redmatrix.setTextSize(0);
    Redmatrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Redmatrix.setTextColor(LED_ON);
    Redmatrix.setRotation(1);
    Greenmatrix.setTextSize(0);
    Greenmatrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
    Greenmatrix.setTextColor(LED_ON);
    Greenmatrix.setRotation(1);
       BuzzersReady();

}
 
 
void loop(void) {
  
		  if (ReadytoPlay ==1)
		    {
		    ReadREDbutton();
		    delay (5);
		    }
		  if (ReadytoPlay ==1)
			{
			ReadBLUEbutton();
		    delay (5);
			}
		  if (ReadytoPlay ==1)
		    {
		    ReadGREENbutton();
		    delay (5);
		    }
		  if (ReadytoPlay ==1)
		    {
		    ReadYELLOWbutton();
		    delay (5);
		    }
		  if (ReadytoPlay ==0)
			{
			Read_Instructor_Buttons(); 
			 delay (5);
			 }
}

void   ReadREDbutton()
{
    buttonREDState = digitalRead(buttonRED); 
    if (buttonREDState != lastbuttonREDState) {
    if (buttonREDState == LOW) {
       Serial.println("RED Buzzed In");
       Serial.println(buttonREDState);
       strip.setPixelColor(0, 0, 0, 0) ; // Yellow
       strip.setPixelColor(1, 0, 0, 0) ; //Blue
       strip.setPixelColor (2, 0, 255, 0) ; //Red
       strip.setPixelColor(3, 0, 0, 0) ; //Green
       strip.show();
      analogWrite(Red_Light, 255); 
  
      ReadytoPlay =0;
      BuzzedIn =1; //red
      Redmatrix.clear();
      Redmatrix.setCursor(2,1);
      Redmatrix.print("**");
      Redmatrix.writeDisplay();
      } 
      lastbuttonREDState = buttonREDState;  
  }
}  

void   ReadBLUEbutton()
{
    buttonBLUEState = digitalRead(buttonBLUE); 
    if (buttonBLUEState != lastbuttonBLUEState) {
    if (buttonBLUEState == LOW) {
     Serial.println("BLUE Buzzed In");
     
      strip.setPixelColor(0, 0, 0, 0) ; // Yellow
       strip.setPixelColor(1, 0, 0, 255) ; //Blue
       strip.setPixelColor (2, 0, 0, 0) ; //Red
       strip.setPixelColor(3, 0, 0, 0) ; //Green
       strip.show();
      analogWrite(Blue_Light, 255); 
     
     ReadytoPlay =0;
     BuzzedIn =2; //blue
     Bluematrix.clear();
     Bluematrix.setCursor(3,1);
     Bluematrix.print("**");
     Bluematrix.writeDisplay();
      } 
      lastbuttonBLUEState = buttonBLUEState;  
  }
}  
     
void   ReadGREENbutton()
{
    buttonGREENState = digitalRead(buttonGREEN); 
    if (buttonGREENState != lastbuttonGREENState) {
    if (buttonGREENState == LOW) {
   Serial.println("Green Buzzed In");
   
   strip.setPixelColor(0, 0, 0, 0) ; // Yellow
       strip.setPixelColor(1, 0, 0, 0) ; //Blue
       strip.setPixelColor (2, 0, 0, 0) ; //Red
       strip.setPixelColor(3, 255, 0, 0) ; //Green
       strip.show();
      analogWrite(Green_Light, 255); 
   
   
    ReadytoPlay =0;
    BuzzedIn =4; //Green
     Greenmatrix.clear();
    Greenmatrix.setCursor(2,1);
    Greenmatrix.print("**");
    Greenmatrix.writeDisplay();
      } 
      lastbuttonGREENState = buttonGREENState;  
  }
}  


void   ReadYELLOWbutton()
{
    buttonYELLOWState = digitalRead(buttonYELLOW); 
    if (buttonYELLOWState != lastbuttonYELLOWState) {
    if (buttonYELLOWState == LOW) {
       Serial.println("Yellow Buzzed In");
    ReadytoPlay =0;
    
    strip.setPixelColor(0, 255, 255, 0) ; // Yellow
       strip.setPixelColor(1, 0, 0, 0) ; //Blue
       strip.setPixelColor (2, 0, 0, 0) ; //Red
       strip.setPixelColor(3, 0, 0, 0) ; //Green
   strip.show();
  analogWrite(Yellow_Light, 255); 
    BuzzedIn =3; //Yellow
     Yellowmatrix.clear();
    Yellowmatrix.setCursor(2,1);
    Yellowmatrix.print("**");
    Yellowmatrix.writeDisplay();
      } 
      lastbuttonYELLOWState = buttonYELLOWState;  
  }
}  

 
void BuzzersReady ()
{
  Serial.println("Get your buzzers ready");

   for (int8_t x=7; x>=-46; x--) {
    Redmatrix.clear();
    Redmatrix.setCursor(x,0);
    Redmatrix.print("Get Ready");
    Redmatrix.writeDisplay();
    Bluematrix.clear();
    Bluematrix.setCursor(x,0);
    Bluematrix.print("Get Ready");
    Bluematrix.writeDisplay();
    Greenmatrix.clear();
    Greenmatrix.setCursor(x,0);
    Greenmatrix.print("Get Ready");
    Greenmatrix.writeDisplay();
    Yellowmatrix.clear();
    Yellowmatrix.setCursor(x,0);
    Yellowmatrix.print("Get Ready");
    Yellowmatrix.writeDisplay();
    delay(40);
    
      strip.setPixelColor(0, 0, 0, 0) ;
        strip.setPixelColor(1, 0, 0, 0) ;
         strip.setPixelColor(2, 0, 0, 0) ;
          strip.setPixelColor(3, 0, 0, 0) ;
       strip.show();
     analogWrite(Red_Light, 0); 
     analogWrite(Green_Light, 0); 
     analogWrite(Blue_Light, 0); 
     analogWrite(Yellow_Light, 0); 
  }
  DisplayScore ();
    BuzzedIn =0;
  ReadytoPlay =1;
 
}
 

void Read_Instructor_Buttons()
{
	int instr_buttons = 0;
	int b;
	instr_buttons = analogRead(A0); 
  	//Serial.print("analogRead =  ");
  //	Serial.println(instr_buttons);
  	delay(100);
  	if (instr_buttons <20 ) 
	  	{
	  	ButtonCorrect();
	  	}
	else if (instr_buttons > 60 && instr_buttons < 80) 
		{
		ButtonReset();
		}
	else if (instr_buttons > 110 && instr_buttons < 130) 
		{
		ButtonWrong ();
		}  	
  

}
void ButtonReset()
{
      Serial.println("RESET");
      Serial.println(ReadytoPlay);
      BuzzersReady();
}


void ButtonCorrect()
{
     Serial.println("CORRECT");
     Serial.println(ReadytoPlay);
   	//whoever has buzzed in should get some points. 
    switch (BuzzedIn)
    {
    case 1: //red
     RedNumberCorrect = RedNumberCorrect++ ;
      break;
    case 2: //blue
    BlueNumberCorrect = BlueNumberCorrect++ ;
      break;
    case 3: //yellow
    YellowNumberCorrect = YellowNumberCorrect++ ;
      break;
    case 4: //green
    GreenNumberCorrect = GreenNumberCorrect++ ;
      break;
    }
    BuzzersReady ();
  }

void ButtonWrong()
{
    Serial.println("WRONG");
    Serial.println(ReadytoPlay);
    switch (BuzzedIn)
    {
    case 1: //red
     RedNumberCorrect = RedNumberCorrect-2;
      break;
    case 2: //blue
    BlueNumberCorrect = BlueNumberCorrect-2;
      break;
    case 3: //yellow
    YellowNumberCorrect = YellowNumberCorrect-2 ;
      break;
    case 4: //green
    GreenNumberCorrect = GreenNumberCorrect-2 ;
      break;
    }
    BuzzersReady ();
}




void DisplayScore()
{
  Bluematrix.clear();
  Redmatrix.clear();
  Greenmatrix.clear();
  Yellowmatrix.clear();
  Serial.println(" ");
  Serial.println("Score so far");
  Serial.print("Red Team:" ); 
  Serial.println(RedNumberCorrect); 
  Serial.print("Blue Team:" ); 
  Serial.println(BlueNumberCorrect); 
  Serial.print("Yellow Team:" ); 
  Serial.println(YellowNumberCorrect); 
  Serial.print("Green Team:" ); 
  Serial.println(GreenNumberCorrect); 
  

    if (RedNumberCorrect <= 9 && RedNumberCorrect >=0)
    {
      Redmatrix.setCursor(11,1);
    }
   if (RedNumberCorrect <0 && RedNumberCorrect >= -9)
     {
      Redmatrix.setCursor(5,1); 
     }
     
   if  (RedNumberCorrect >= 10)
     {
      Redmatrix.setCursor(5,1); 
     }
   if  (RedNumberCorrect <= -10)
     {
      Redmatrix.setCursor(-1,1); 
     }
 
    
  Redmatrix.print(RedNumberCorrect);
  Redmatrix.writeDisplay();
  
      if (BlueNumberCorrect <= 9 && BlueNumberCorrect >=0)
    {
      Bluematrix.setCursor(11,1);
    }
   if (BlueNumberCorrect <0 && BlueNumberCorrect >= -9)
     {
      Bluematrix.setCursor(5,1); 
     }
     
   if  (BlueNumberCorrect >= 10)
     {
      Bluematrix.setCursor(5,1); 
     }
   if  (BlueNumberCorrect <= -10)
     {
      Bluematrix.setCursor(-1,1); 
     }
  
  
  Bluematrix.print(BlueNumberCorrect);
  Bluematrix.writeDisplay();
  
  
       if (YellowNumberCorrect <= 9 && YellowNumberCorrect >=0)
    {
      Yellowmatrix.setCursor(11,1);
    }
   if (YellowNumberCorrect <0 && YellowNumberCorrect >= -9)
     {
      Yellowmatrix.setCursor(5,1); 
     }
     
   if  (YellowNumberCorrect >= 10)
     {
      Yellowmatrix.setCursor(5,1); 
     }
   if  (YellowNumberCorrect <= -10)
     {
      Yellowmatrix.setCursor(-1,1); 
     } 
  
 
  Yellowmatrix.print(YellowNumberCorrect);
  Yellowmatrix.writeDisplay();
 
        if (GreenNumberCorrect <= 9 && GreenNumberCorrect >=0)
    {
      Greenmatrix.setCursor(11,1);
    }
   if (GreenNumberCorrect <0 && GreenNumberCorrect >= -9)
     {
      Greenmatrix.setCursor(5,1); 
     }
     
   if  (GreenNumberCorrect >= 10)
     {
      Greenmatrix.setCursor(5,1); 
     }
   if  (GreenNumberCorrect <= -10)
     {
      Greenmatrix.setCursor(-1,1); 
     } 
 
  Greenmatrix.print(GreenNumberCorrect);
  Greenmatrix.writeDisplay();
  
}

Comments

onion2 (author)2017-03-05

the link for the led matrix does not work :/
but great instructable !

JScottMO (author)onion22017-03-05

Humm, Sorry about that, I'll try to correct. Glad you liked it!

About This Instructable

1,892views

35favorites

License:

Bio: Most days, I am an Assistant Teaching Professor at the University of Missouri and a small business owner with decades of experience in project management ... More »
More by JScottMO:Center for the Digital Globe Class ProjectBitcoin Price TickerGame Show Controller 1.0
Add instructable to: