A Game That Does More With Less

[David Johnson-Davies] created a minimal Secret Maze Game using a single ATTiny85 and a few common components. This simple game uses four buttons, four LEDs, and a small speaker. The player moves in the four cardinal directions using buttons, and the LEDs show walls and corridors. If an LED is lit, it means the path in that direction is blocked by a wall, and attempting to move in that direction will make a beep. When the player reaches the exit, a short victory tune chirps from the speaker.

Sample maze. A 16×16 matrix is allocated for maze designs.

Since the ATTiny85 has only five I/O lines, [David] had to get a bit clever to read four buttons, display output on four LEDs, and drive a little speaker. The solution was to dedicate one pin to the speaker and the other four to charlieplexing, which is a method of driving more LEDs than you have pins. It takes advantage of the fact that most microcontroller pins can easily switch state between output high, output low, or low-impedance high-impedance input.

As for the buttons, [David] charlieplexed them as well. Instead of putting an LED in a charlieplexed “cell”, the cell contains a diode and an SPST switch in series with the diode. To read the state of the switch, one I/O line is first driven low and the other I/O line is made an input with a pullup. A closed switch reads low on the input, and an open switch reads high. With charlieplexing, four pins is sufficient for up to twelve LEDs (or buttons) in any combination, which is more than enough for the Secret Maze.

Charlieplexing is also what’s behind this 110 LED micro-marquee display, or this elegant 7-segment display concept that takes advantage of modern PCB manufacturing options.

17 thoughts on “A Game That Does More With Less

  1. So basically, with this you play maze without seeing the maze. A non-video computer game :-)

    Since it already has a beeper, perhaps even the four LEDs are superfluous, you could just have various sounds instead, confirmation beep, unable-to-execute beep, and win beep. Then it could be played by visually-impaired players, too. Or, keep both visual and audible cues, so that it could be played by all people who hear or see. Now, for people who neither hear nor see, there should be some sort of haptic feedback, and beeper might be able to provide that, if its membrane is made accessible by a touch. I assume it is possible to feel difference between high pitch vibration and low pitch vibration?

    And keys, for maze, you only need only two keys: rotate and advance. Or even, one key with short press for rotate and long press for advance. However, any press timing based command interface would frustrate players, especially if score depends on puzzle solving total time.

  2. alternative1:
    with 6 I/O lines, one can be AI to read the 4 buttons (each one pressed give different resistance, so ADC can understand what button is pressed).
    One DO goes to PVM for beeper
    4 DO goes for the 4 leds.
    All 6 I/O are used.

    Alternative2:
    as above but If you charlieplexed the 4 leds with 3 DO, you save one more I/O for further activities.

    less is more!

    1. “less is more”

      So it it really “less” to add 4 resistors to the BOM to use the analog read technique?

      I wonder if he can get rid of some those passives by treating the leds and buttons each as a 2×2 matrix using 4 IO lines, and then scanning the matrix between refreshes of the LEDs. 2 resistors for the LEDs, no diodes?

      See how engineering isn’t quite so straightforward? :)

      1. the “game” is to save I/O. ADC is already available so it costs 0. Ok it is necessary to add 4 resistors, in my opinion it worth to add 4 resistors to have this gain.

        i wonder also if it is possible to use the charlyplexing tecnique and use the I/O as DO for leds and as DI to read buttons, this whould be the best solution o have the goal with the minimum I/O (and BOM).

        1. Wow, whoever told you that was the “game” really screwed you up.

          You think it’s better to increase your parts count, cost, complexity, points of failure, and difficulty of construction all to save IO pins that will go unused. Wow.

          By your logic, use a port multiplier, then you only need 1 IO line on the MCU and I win your “game”.

          Your “game” is nonsense. Minimize parts and complexity.

  3. When you go into a maze, place a hand on the wall and walk, without taking your hand off the wall. You’ll go into dead ends, but keep going, without taking your hand off the wall. You’ll come out of the maze eventually.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.