Racing

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

  1. Attach the shield onto the top of the Arduino board.
  2. Connect five LEDs across breadboard gap.
  3. Connect a 220 ohm resistor to digital pin 9. Connect the resistor to the long leg of the first LED.

     

  4. Connect each of the digital pins 10 through 13 to a corresponding LED following the same method.
  5. Connect the short leg of the LEDs to GND using black jumper wires.
  6. Using a separate breadboard, connect a 1M ohm resistor between digital pin 2 and digital pin 3.
  7. Connect digital pin 4 to digital pin 2 following the same method.
  8. Make a capacitive sensor by cutting a 5cm x 5cm square of aluminum foil. Wrap one corner of a foil square to a loose jumper wire – the metal of the wire must contact the foil.
  9. Make two capacitive sensors and connect each to digital pins 3 and 4 – tape the two sensors firmly to the table making sure they do not touch.
  10. Connect the Arduino assembly to the computer, upload example ‘Racing’ and try the game out.

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 and scoreBoard.
  • The capacitive switch variable and objects are declared, capacitiveSensorThreshold, leftFoot and rightFoot.
  • 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 the leftFoot capacitive switch is pressed, that is touched.
  • The LED in the VU-meter position LED is turned on. The first time loop() 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 as score/20. The 20 first time loop() runs LED will be equal to 0, the next 20 times loop() runs LED 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 and score is set to 0.
  • If score is not more than 100, the program continues at the beginning of loop().

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).