- Concept
I created a new project for this week—a button pressing game!
This is what the “user interface” looks like: LEDs and pushbuttons of four colors, along with a potentiometer.
The rule of my game is that, after the game starts, 1-3 LEDs will be lighted during each round of the game. The player is supposed to press all the buttons whose colors are not lighted to advance to the next round. If the player accidentally hits a lighted color or fails to press all the buttons required within the time limit, he will be informed of his mistakes and then return to the pregame state, where all LEDs keep blinking until the player restarts the game.
The tempo of the game as well as the blinking rate of the LEDs can be controlled with the potentiometer. To control the settings, rotate the knob clockwise to accelerate; rotate to the leftmost position to “power off”; press all four buttons together to start, pause, or resume at any time of the game.
- Circuit schematic
- Program
- Behavior
The potentiometer serves as the analog sensor whereas the pushbuttons serve as digital sensors. In the pregame state, all LEDs are controlled in an analog fashion as their brightness increments and decrements periodically at the rate controlled by the potentiometer. On the other hand, once the game starts, LEDs are controlled in a digital fashion as they are set to either HIGH or LOW to blink.
- Problems and solutions
- When I was building my circuit, I realized there was not enough space to arrange the four buttons into a square as each has to straddle the center trench of the breadboard. Then, when I put them in a row, there was still not enough space for all the external resistors. So in the end, I utilized Arduino’s pull-up resistors for all the pushbuttons.
- When testing the game, I noticed that Arduino processed my input so quickly that, after I pressed the correct buttons, it often proceeded to the next round before I could remove my fingers from the buttons, which caused me to lose the next round. Therefore, I added some delay time after each round. Likewise, I also added some delay when Arduino detects a wrong button being pressed so as to allow time for the player to press all the intended buttons.