This was a fun little LCD project I spent an afternoon putting together. It’s based on a whole family of single button obstacle avoidance games. In short you move your helicopter up and down to avoid obstacles, scoring points for the distance travelled before inevitably crashing.
The components of the hardware build are pretty straight forward:
- S1 & R3 make up the games input and are tied to interrupt 0 (D2) on the Arduino. The sketch has some code for forcing a frame update when the button state changes, and a mediocre button debouncing.
- R1, R2 & T1 give the sketch control over the displays back light. I didn’t have it implemented when I took the video but the display now flashes on and off dramatically when you crash.
- R4 is the screens mandatory contrast adjust
The software is a little less straight forward and consumed the vast majority of the build time. Most of the work focused on optimizing how fast I could push data to the screen using the built in LiquidCrystal library. Some of the highlights:
- %99.9 delay() free, all the timing in the sketch is done using millis() because it is non-blocking and good practice. The only delay in the sketch is used to help seed the random number generator with noise from analog 0 (A0).
- All the animated game sprites are done by cycling through a set of custom characters. After doing the video I updated all of the game sprite to look like buildings and birds/airplanes (if you use you imagination a bit).
- Collision detection and game state is done using bitwise operations on 2 unsigned 16-bit integers. I also use these two variables to ensure that the game never produces an impassable wall the player has no choice but to crash into.
- High scores are stored in the Arduino’s EEPROM and use a very simple checksum to make sure the score is actually from the helicopter game.
- The game gets faster and harder the longer you play.
Sketch & Schematics
If anyone is interested in doing their own version I have included the Eagle schematic and Arduino sketch: Eagle schematic & Arduino sketch
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.