The heart of the game is ATtiny13. It is low power AVR 8-bit microcontroller with 1 kB flash memory, 64 bytes EEPROM and 64 bytes SRAM.
It has six I/O pins, from which one acts as a reset and is used to start a new game, four are connected to LEDs and buttons and the last one leads to the magnetodynamic buzzer. The device is powered from CR2032 lithium cell.
As mentioned, the device contains four LEDs of different colors (red, orange, yellow and green) connected with four button switches. (Blue or 525 nm green LEDs can't be used because they have too high forward voltage and wouldn't work well with partially discharged battery.)
After pressing each of those buttons, the LED lights up and information about the button state can be read by a microcontroller. The pins of a microcontroller are bi-directional, so they can be changed from input to output in any time and can control LEDs instead of the buttons (see simplified diagram).
To avoid to making short-circuit on output pins, changing between input and output can be done only in low state (disabled internal pull-up resistor). Because each LED has different efficiency, resistors of different values must be connected in series with them.
The high-impedance (42 ohm) buzzer is connected in series with a capacitor (to eliminate DC voltage) to the output of internal 8-bit timer/counter. Like in an original game, each color is producing a particular tone when it is pressed or activated by the microcontroller and the frequencies are in an exact ratio 3:4:5:6 (50% duty cycle).
Sufficient pseudo-random sequences are generated by a linear congruential generator defined by the recurrence relation:
x[i+1] = (2053 * x[i] + 13849) mod 216
Eight bit pairs of 16-bit number x[i] are XORed together to produce a number 0 to 3. Quality of this generator can be checked displaying the whole 65536 elements long sequence (it is good enough for this purpose).
The value of random seed x is generated from combination of non-connected input of A/D converter and jitter between watchdog timer and calibrated RC oscillator. So the probability of repeating the same sequence is very low.
The watchdog timer is used also for buttons debouncing and for auto power-off after a minute of inactivity. In power-down mode (also after the game is over) the consumption is approximately 0.15 microamps.
Best score is saved to the EEPROM (including the seed), so it is possible to re-play the best game (even after removing the battery).
The concept of this electronic set is to make it easy to build without any special tools or skills. The single-sided printed circuit board is optimized to be easily drawn by hand with a permanent marker and etched in a solution of ferric chloride (tested at summer camps and hobby groups for children).
The game can run in five modes:
- When the game is started only using the middle (reset) button, random seed is generated and you have to memorize and repeat increasing sequence of colors and tones. In higher levels the game goes faster. If you make a mistake, the correct LED blinks three times and game-over animation is played. If you have beaten the best score, your game (achieved level and seed value) is saved to the EEPROM and best-score animation is played.
- If you hold orange button during reset, you can continue with the best-scored game. It starts on the highest achieved level.
- When you hold yellow button during reset, you can play the best-scored game from the beginning.
- If the red button is pressed during reset, the best score is erased and you start a new random game as in the first case.
- Pressing the green button during reset starts playing the pseudo-random sequence (starting by a random seed). It takes almost 3.5 hours before the sequence starts repeating.
This project with exception of the software is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. The software (source and binary) is licensed under the MIT License.