Step 1: Make it
What is it?
Make a reaction game with real physical switches you can bash as hard as you like!

How it works
- Make two physical input switches using cardboard and tin foil – similar to the ones used in the Pressure switch alarm project.
 - Connect them to the micro:bit pins as in the picture – one tin foil pad on each switch goes to the micro:bit’s GND pin, and the other is connected to pin 1 or pin 2 depending on whether you are player A or player B.
 - The program waits a random time between 1 and 5 seconds, then shows a heart on the LED display output.
 - You can’t hit your button before it lights because it uses Boolean logic to stop anyone cheating! Boolean variables can only have two values: True or False. The game started variable prevents either player pressing their button too soon by only checking which button is pressed while the game has started.
 - An infinite loop keeps the game running so you can keep playing.
 
What you need
- 1 micro:bit
 - 4 crocodile clip leads
 - Some scrap cardboard, tin foil, glue and scissors
 
Step 2: Code it
1from microbit import *
2import random
3
4while True:
5    gameStarted = False
6    sleep(random.randint(1000, 5000))
7    gameStarted = True
8    display.show(Image.HEART)
9    while gameStarted:
10        if pin1.is_touched():
11            display.show('A')
12            gameStarted = False
13        elif pin2.is_touched():
14            display.show('B')
15            gameStarted = False
16    sleep(3000)
17    display.clear()
18Step 3: Improve it
- Use variables to keep track of each player’s score
 - Add a timer to show how quick each winner’s reaction was
 - Track which player has the fastest reaction time
 
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.


