Fencing

En garde! Test your reaction time against an opponent!

In this game, two players will hold tilt switch swords. When the green LED randomly lights up, the first person to swing their sword wins.

Materials

  • 1 Arduino board
  • 1 Basic Education shield
  • 2 Tinkerkit tilt switches
  • 2 Tinkerkit long cables
  • 1 big red LED
  • 1 big green LED
  • 2 big yellow LEDs
  • 4 220 ohm resistors
  • 4 black jumper wires
  • 4 coloured jumper wires

Instructions

  1. Attach the shield onto the top of the Arduino board.
  2. Connect four LEDs across breadboard gap in the following order – yellow, red, green, yellow.
  3. Connect a 220 ohm resistor to digital pin 2. Connect the resistor to the long leg of first LED.
  4. Connect each of the digital pins 3 through 5 to a corresponding LED following the same method.
  5. Connect the short leg of the LEDs to an Arduino GND pin using black wires.
  6. Connect Tinkerkit tilt switches to D9 and D10.
  7. Connect the Arduino assembly to the computer, upload example “Fencing” and try the game.

Code

You can find the code in File -> Examples -> Castilla -> Sports -> Fencing


How it works

When the game begins, the red LED lights up indicating both of players should hold their tilt switch sword upright and wait. The program waits for a random period of time, after which the red LED will turn off and the green LED will turn on.  The game then waits for either of the tilt switch swords to swing, and the first to do so will be the winner. The yellow LED on the winners side will light up for a few seconds, and the game starts over again.

 

Troubleshooting

  1. Refer to the illustrations and double check your connections. Make sure the shield and wires are firmly connected. Check the LED polarities to make sure they are consistent and properly wired.
  2. You hit first but your friend wins? Try swapping your tilt switch swords.
  3. Nothing happens when you are swinging the sword? Make to hold the tilt switch upright on red and wait for the green light, and see the reference for debugging tilt switches.
  4. VU-meter does not work correctly? See reference for debugging VU-meter.

Experiment further

  • Construct a couple of swords to house the tilt switches inside.
  • Change the winning conditions. Can you make it so that the person who is first to swing the sword up and down five times is the winner?