How to play:
When first powering on, ensure the sensor is not covered by shadow
Keeper of the Flame offers two different modes - an easy 1 minutes journey, or a more challenging 3 minute journey. When the game is first powered on the blue light will come on, cover the sensor until it turns off to select the hard mode, or leave the sensor uncovered to select easy mode. The game will light the yellow LED to indicate the game is in easy mode, or the blue LED to indicate hard mode.
After this the blue LED will rapidly blink three times and the game will then begin.
Your torch can lose health in two ways, either being uncovered when it is raining (blue light on) or covered when it is not. As the torch loses power the yellow LED will continue to grow weaker until it dies. Act quickly to cover and uncover the sensor; the flame will not regain any lost health.
Victory is achieved by surviving the trip out of the woods (the yellow LED will go solid and then begin to blink to indicate this) or if you fail the blue LED will light up in a similar manner.
To play again, turn off the game and turn it back on
Components:
1 - Raspberry Pi Pico
2 - LEDs (1 yellow, 1 blue)
1 - 55 Ohm resistor
1 - 1k Ohm resistor
1 - 5k Ohm resistor
1 - Photo resistor, 5k - 55k Ohm (I salvaged mine from an old nightlight)
2 - 10 uF capacitors
1 - 7805 regulator
1 - DPST switch
The only input is the photo resistor, this is used in a voltage divider, allowing the pico's ADC to get a meaningful reading to determine the state (shaded/un-shaded). Output is provided by the LEDs with the blue LED being a simple IO pin, while the yellow LED is controlled by a PWM signal.
Code:
The game is programmed using micro python, and can be seen here on github. A few convenience functions were written to:
Read the photo-resistor by taking an ADC measurement
Calibrate the sensor by averaging 20 readings, and
Blink the lights - which takes a count of blinks and the duration per blink (in seconds).
The game goes through the following phases -
-Mode selection (Easy, 60 seconds & Hard 180 seconds)
-Game Play
-Results output
Please review the code to see how this was done. A map and clamp function were also written allowing for a simple means to link the PWM signal to the remaining health, and a little random noise adds a nice flicker effect to our 'flame'
Building the case:
"Making an enclosure is a lot like being a good lawyer - you have to build a strong case if you want to be successful."
Finally, to give the game more visual appeal I made a case from solid walnut. This was done by gluing a couple scraps or walnut together and cutting them down to the dimensions of 3" x 4" x 1&3/4" chunk. Using the bandsaw a thin slice was taken off to create the back plate for our enclosure before holes were measured and drilled for the LEDs and photo-resistor. With that done a 15mm forstner bit (Yes mixed units... yay Canada!) was used on the drill press to remove the bulk of the material from inside.
A bit of clean up with chisels, gouges, and files was used to fine tune the edges and ensure everything fit inside.
After sanding the case up to 400 grit I used a flat bed scanner to scan the front of the case and design the art work. The artwork was engraved into the front with a laser before being filled in with paint (I always forget the walnut doesn't take laser engraving as well as I'd like) and sanded back. Finally the case was finished with a mineral oil and beeswax finish to bring out the full beauty of the walnut.
Fitting the electronics:
With the case made all that remained was to fit the electronics in. Everything was point to point soldered, covered in heat shrink and hot glued into place. I also made sure there was enough flex in the wires to let the pico move up enough to be connected by USB (should I ever want to play with the code in the future or tweak the game). The last step was to screw the back plate on sealing the case (I used brass screws to compliment the walnut) and completing the project.
Final Thoughts:
I enjoyed this project, making a UI/Game using only 1 component for input was an interesting challenge. My main takeaways from this were:
- Always give yourself a little more room then you'll think you'll need. I had a bit of a challenge getting everything to fit inside nicely, even an extra 1/4 inch would have saved me some stress.
- I love hot glue - electrical isolation and strain relief in one cheap source!
- I hate hot glue - stringy, burny, horrible stuff - but having a silicone mat makes it a lot better to work with.
- Fit and finish matter. I was happy when I had this working on the breadboard, but having the game as something I can proudly show off - that looks like an actual product and feels good in the hand - really brings it to the next level. Put a little time into making things look pretty.