By Joe Farr, International Man of Mystery
Some time ago I created an electronic version of the game Mastermind. This project used 44 RGB LEDs, 44 bicolour LEDs, several 7-segment LED displays, numerous 74HC595 shift registers, and a PIC microcontroller. While this did work, it required a large PCB, extensive soldering, and was rather expensive due to the high part count. All-in-all, it was rather excessive to play just one game.
Enter the WS2812 addressable LED. These devices integrate three individual LED die (red, green, and blue). Each device is controlled by a 24-bit word, which is formed from three 8-bit bytes that adjusts the brightness of each die via an in-built pulse-width modulation (PWM) module, thereby allowing a wide range of colours to be generated. Once set, they remember their colour until you change it or the power is reset, so no more frantic multiplexing.
WS2812 LEDs are available in a variety of form factors, including individually or pre- mounted on rigid or flexible PCBs. They are also available on reels of tape around 10mm wide that are often used as decorative lighting around the home (under cupboards and in wall units etc). I opted for a 1-meter length of hi-density tape with 144 LEDs per meter. These LEDs require precise signal timing, but this is easily achievable using a PIC microcontroller and some carefully crafted code.
I cut the tape into ten strips of fourteen LEDs each, adhered them to a piece of plexiglass to form a 10 x 14 matrix, then connected the strips “head-to-toe” to form one long chain. To prevent light bleed between LEDs, I laser-cut a mask from plexiglass. I also discovered that placing tracing paper between the LEDs and the mask diffused the light, producing a more pleasing and uniform colour.
Glueing together cut-to-size plexiglass pieces, I constructed an enclosure, adding eight push buttons and a 9-pin expansion connector for an external gamepad. I wanted a vintage console “feel” with game programs stored on plug-in cartridges. I initially planned to use EEPROMs for game program storage, but this would have required some type of boot loader to read the code from the EEPROM and write it to the PIC’s program memory for execution.
Ultimately, I decided to use pre-programmed PICs mounted on small plug-in PCBs as my game cartridges. In addition to reducing complexity, this
will facilitate adding additional hardware for future projects if required. The games I’ve written thus far (Tetris, Mastermind, and Snake) all utilise the same basic cartridge. However, if future endeavours require additional hardware— maybe for sound or additional memory—this won’t be a problem as I’ll just design an enhanced PCB and not have to modify the main console.
Inside the console, a 7805 LDO regulator drops the voltage from six AA rechargeable batteries to 5V, and powers the main LED matrix, three dual 7-segment display modules, and the cartridge PCB. Each 7-segment module includes two digits and two 74HC595 shift registers creating a chain of six digits that can be used to display game scores and other information.
The cartridge connector interfaces with power, push buttons, keypad expansion connector, 7-segment display data chain, and the main LED matrix. Each cartridge contains a PIC18F25K22 microcontroller plus other discrete components. For development purposes, I included a connector compatible with my PIC in- circuit programmer, facilitating rapid program iteration.
This is an excellent way to learn or improve one’s programming skills and these games from yesteryear are still great fun to play.
Got a design project you’d care to share? Contact our Editor: [email protected]