🐍 CircuitPython is the easiest way to program microcontrollers now celebrating over 200 boards!🐍

Reaction Game for CPx
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Reaction Game for CPx

by ron_g on Thu Dec 21, 2017 3:49 pm

Adabox006 delivered my first CPx. I recently purchased the Feather M0 Express but hadn't even put headers on it yet so the CPx was my first real chance to play with it and Circuit Python. I pretty quickly had the idea to use the 10 neopixels to create a game that tested reaction time and it was quite simple to do. Below I will described what I used, link to a video of the game in action, as well as link to the readme and code.py on Github.

The BOM is trivial as it only requires the CPx and a power source. You can power it from a USB cable but that's not very convenient since you need to hold it in your hand and react quickly. I power mine with a small lipo battery I attached to the back of the CPx using Scotch double-sided tape but it can also be powered using the AAA holder that came with Adabox006.

The project allowed me to learn about the specifics of several features on the CPx:
    - Neopixel control
    - Random number seeding
    - Using the alligator clip pads as "buttons" based on capacitive touch
    - Playing simple tones
    - Reading button pushes from buttons A and B

A picture/video is worth a thousand words so you might prefer to simply see what this game looks like and see me show some of the features (while winning and losing!). This YouTube video will give you all you need to know to play the game: https://youtu.be/4_RTuax43IQ. If you prefer a text description here is the short summary:
    - The neopixels will cycle counter clockwise. All will be blue except one which will be red which is the player's target
    - The object of the game is to touch the pad A7 right when the target LED changes to red (random location for each game)
    - When first started the neopixels will all flash blue except for #1 being RED indicating the initial difficulty setting of 1 (easiest)
    - Press push button B to start the game. All of the neopixels will turn off for 1 second so you can prepare then they begin cycling until you touch A7
    - If you get it right a little victory tone set is played and all the neopixels turn GREEN
    - If you miss then there is a sadder tone and the neopixels go RED
    - You can hit push button B to play again
    - If you want to increase the difficulty, because level 1 is quite easy, press push button A to advance dfficulty from 1 to 5. The number of RED neopixels shows the current difficulty setting
    - Difficulty 5 has the game run as fast as it can and is pretty challenging

The code is hosted on Github if you want to try it out: https://github.com/ronguest/Reaction-Game. I can imagine a number of easy variations on this game so it might be a good start for your experiments.

Posts: 156
Joined: Tue Apr 05, 2011 6:21 pm

Please be positive and constructive with your questions and comments.