The "Lights and Sounds" buzzers need to be modified so that we can bring a "button" pressed signal to the Arduino controller, and then, when appropriate, send a signal to the button to flash it's lights and play it's sound.
We accomplish the button modificaions by cutting the PC board and intercepting the button presss signal. We then activate the lights/sounds by driving the other side of the "cut" line. We bring the two lines (button press, and activate) along with a ground line from the button to the control box with a standard 2.5mm stereo male to male cable.
Using a standard "project box" we drill 4 holes to hold LED's and another hole for the reset button. Then we drill smaller holes for the 2.5mm audio jacks. The Arduino controller is placed in the box, the whole thing is wired together, and we are done!
We'll go through the process step by step below.
The control box construction is fairly strightforward. To handle the 4 colored buttons we need:
The control box provides several functions:
The schematic below shows the components and interconnections.
We used a project box with approximate dimensions of 6” wide x 3 3/4” depth x 1 3/4” high. Any size that fits the components will do. It might be nice to fit batteries inside the box, but we used the power connector with an external supply, either AC or battery powered. The general steps we followed were:
Make sure you have a way to fasten the UNO to the control box. Use stand-offs if necessary.
Below are some pictures of our unit from different angles.
If you are not familiar with programming the Arduino, take some time before proceeding to learn the basics of programming the Arduino. The Arduino Uno has a convenient USB port that provides a connection to the computer and also powers on the Arduino from USB power. You need to know how to program the Arduino and download programs to it so that you can download the program with these instructions into the Arduino. Or... you can also create your own variations. It’s one of the great aspects of this project, is the possibilites are limitless!
OK, now that you are familiar with the Arduino Uno and can load a progam to it, we will go over the operation of V1.1 of the program supplied with these instructions.
The behavior we want to achieve from the control box is as follows:
We will go over some of the key approaches and techniques in the program.
Many of the Arduino example programs will use the delay(n); statement to achieve blinking LED’s. Given that we want to not only capture what button was pressed 1st, but also the buttons after this, the “delay” approach will not work for us. Wonder if the 1st button was pressed and we were in a loop to drive the LED with a 500 ms (1/2 second) delay. 1/2 second is a LONG time and there might have been two or even three buttons pressed during the “delay” time and we would have no way of knowing about it! Several things could happen, when we read the buttons, all three are pressed, or perhaps one is pressed because the other button was pressed and released already! This would make the players very unhappy with our game.
So, we cannot use the “delay” function. Instead we will program the “void loop()” logic in a “polling” method. Basically this means we will try to miniminze any delays in our code and keep looping over and over again checking the status of the buttons. We will also see if it’s time for us to change the status of a LED or buttton. In a timing of the pooling loop in V1.1 we measured the average time spend in the loop to be about 0.1ms or 100 microseconds. That seems to be a pretty quick loop, and minimizes the chance of multiple button presses happening within a single loop.
But, if the loop is just checking to see if a LED needs to be turned off or on, what tells us what we are supposed to do on any given loop?
To manage the buttons and LED’s we create a “State Sequence Array.” Within the array we define a Profile. An example of a profile is “Blink the lights quickly,” or “Turn on the light.” For each profile there is a sequence of states (or step). For example in the int LED_SEQ array, we define a profile for blinking the lights quickly. That profile consists of the following state definitions:
HIGH, 250, 1, /* Profile 2 (2nd place) begin, step 0 - "Blink Quickly" */ LOW, 250, 0, /* Profile 2, step 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Profile 2 end, step 7 */
So a profile consits of state definitions that have 3 values. The first value is one of three choices, HIGH, LOW, or -1.
The second value is the length of time (in milliseconds) that that state should be in effect before moving to the next state. So Profile 2 in the code fragment above, says to maintain state 1 for 250ms (or 1/4 second) and to also maintain state 2 for 250ms.
The third value is the “next step” or state. In profile 2 step 0, the next step is step 1. The next step after step 1 is step 0. So, you can see that this sequence of states or steps is in a loop. step 0 to step 1 to step 0 and so on.
Defining a “State Sequence Array” lets us easily change the behavior of the buttons and lights by just changing the “program” in the Stage Sequence Array rather than changing C code. For example we experimented with the lights behaving in this way:
In testing this method with a few people they liked a “on solid,” “blink fast,” “blink slowly,” and “off” as the indication of 1st to 4th place respectively.
Note that we made those changes in the light behavior by ONLY changing the profiles in LED_SEQ array and we didn’t have to change the C program at all!
So now that we see how the state (or steps) are defined, how do we keep track of what state the different colored LEDs are in?
The program keeps track of where each color LED is in the “State Sequence Array” (int LED_SEQ array with three variables:
These values are held in the lLSS array for each color. So there are 12 entries. For each of the four colors there are the 3 state sequence variables above. With four colors and three entries for each color, 4 x 3 = 12.
So for each “polling loop” in our code, the LED state machine processing loop does the following:
So, with this program technique, we can change the LED states in complicated ways and STILL watch for button press events in a timely manner. In addition, it’s easy to change the way the LEDS behave without having to change the logic of the C code. We just have to change the profiles and steps in the LED-SEQ array.
In fact this is how we programmed our “Easter Egg” behavior. Can you find it? Do you want to put in your own “Easter Egg” behavior. Go ahead and do it! The job isn’t finished untill the “Easter Egg” is done!
The process for manipulating the button behavior is exactly the same as described for the LEDs above. The Button state variable” containing the “profiles” and “steps” or “sequences” is the int BTN_SEQ array.
Similarily, the current profle and step for each color is maintained in the long lBSS array.
The discussion for the LEDs then applies to the buttons with substitution of the above button variables.
The various variables are declared, and the variable names for the Arduino I/O pin assignments are declared. See the appendix, the code, or the schematic for the Arduino pins used.
The polling loop then consists of the general steps below:
The special case handling of the buttons to independently manage both lights and sound with only one signal line is described in more detail in the section on Button Modifications.
See the appendix for the complete program listing.
Did we miss something that you think would be really neat? For example, perhaps there could be a “Wheel of Fortune” game mode also, where a Color is selected at random, and given a pre-determined amount of time to answer.
Or invent your own new game mode.
That’s the beauty of a microcontroller implemting the logic. Simply create your own program and make it behave exactly the way you want it to.
Let your imagination run wild, and happy Arduino programming!
With a few parts and modified “Sounds and Lights Buzzers” you have a nice looking and very functional Quiz Game Controller.
If you are new to Arduino, then you’ve also learned a lot about using an Arduino in a DIY project.
The final touches include:
We hope that these instructions have been helpful to you.
Our web site at www.projectnotions.com has a video that demonstrates operation of the Quiz Game controller.
If you have questions or comments, feel free to email us.
May all your projects go smoothly!
projectnotions.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.Copyright 2013 projectnotions. All rights reserved.