Run as fast as you can . . . with your fingers!
In this game, a player must tap two sensors alternately in order to run laps. One LED will light up per lap. When all laps are completed, LEDs will blink in victory.
Materials
- 1 Arduino Uno board
- 1 Education Shield
- 1 breadboard
- 5 LEDs
- 2 1M ohm resistor
- 5 220 ohm resistors
- 5 black jumper wires
- 11 colored jumper wires (2 long ones)
- aluminum foil
- masking tape
Instructions
Code
Find the code in File>Examples>EducationShield>Block2-Sports>Projects>Racing
How it works
- The CapacitiveSensor and EducationShield libraries are included.
- The VU-meter variables are declared,
ledPins[]
,pinCount
,LED
andscoreBoard
. - The capacitive switch variable and objects are declared,
capacitiveSensorThreshold
,leftFoot
andrightFoot
. - The variable
score
is declared to hold the score. - In
setup()
, the VU-meter and capacitive switches are configured and initialized. - In
loop()
, the program pauses until theleftFoot
capacitive switch is pressed, that is touched. - The LED in the VU-meter position
LED
is turned on. The first timeloop()
runs this is 0. - The program pauses until the
rightFoot
capacitive switch is pressed, that is touched. - The same LED is turned off again.
score
increases with 1.- The value of
LED
is recalculated asscore/20
. The 20 first timeloop()
runsLED
will be equal to 0, the next 20 timesloop()
runsLED
will be equal to 1 and so on. - As many LEDs are turned on as the value of
LED
. This means that every 20th step one additional LED is turned on. - If
score
is more than 100, all LEDs blink andscore
is set to 0. - If
score
is not more than 100, the program continues at the beginning ofloop()
.
Troubleshooting
- Refer to the illustration and double check your connections. Make sure the shield and jumper wires are firmly connected. Check the LED polarities to make sure they are consistent and properly wired.
- If hitting the foils does nothing, see Capacitive Switch reference for debugging capacitive sensor.
- If VU-meter does not work correctly, see VU-Meter reference for debugging VU-meter.
Learn by doing
- Change the way the LEDs blink when it is game over. See the VUMeter reference for the commands you can use.
- If the game is too easy, make it longer.
- Find other conductive materials to replace the aluminum foil with (maybe your friends).