micro:bit Fast Finger: Reaction Timer
Press button A and wait: at a random moment the whole display lights up. The faster you press A then, the better; your reaction time scrolls past in milliseconds (running_time). Press too early and you get a cross. No extra parts are needed.

Video
Circuit Diagram

Source Code
1# ─────────────────────────────────────────
2# BlueGrays · bluegrays.com
3# micro:bit Fast Finger: Reaction Timer
4# ─────────────────────────────────────────
5# Press button A and wait. At a random moment the whole display lights up:
6# press A as fast as you can. Your reaction time scrolls past in
7# milliseconds. Press too early and you get a cross. No extra parts are
8# needed.
9#
10# Pins:
11# LED -> Onboard 5x5 LED display
12# P5 -> Onboard button A
13# SPEAKER -> Onboard speaker
14
15from microbit import *
16import music
17import random
18
19# ============ SETTINGS ============
20VOLUME = 150 # Volume, 0-255
21WAIT_MIN_MS = 1500 # Shortest wait (ms)
22WAIT_MAX_MS = 4000 # Longest wait (ms)
23LOOP_MS = 50 # Loop pause (ms)
24
25FULL = Image("99999:99999:99999:99999:99999")
26
27set_volume(VOLUME)
28
29while True:
30 display.show(Image.ARROW_W) # Press A
31 while not button_a.was_pressed():
32 sleep(LOOP_MS)
33 display.show(Image.DIAMOND_SMALL) # Get ready
34 sleep(random.randint(WAIT_MIN_MS, WAIT_MAX_MS))
35 if button_a.was_pressed(): # Pressed too early
36 display.show(Image.NO)
37 music.pitch(220, 500)
38 sleep(1000)
39 else:
40 display.show(FULL)
41 start = running_time()
42 while not button_a.was_pressed():
43 sleep(1)
44 reaction = running_time() - start # Reaction time (ms)
45 music.pitch(880, 100)
46 display.scroll(reaction)
47FAQ
What is a good reaction time?
For most people the reaction to a light is between 200 and 300 milliseconds; under 200 is very fast. When you are tired or distracted it takes longer. Do not trust a single try: play five rounds and write down your best result.
What happens if I press before the light?
When the wait is over, the program checks whether the button was pressed. If you pressed early, the light does not come on; a cross shows and you hear a low tone. A second later the arrow is back for a new round. The wait changes every round between 1.5 and 4 seconds, so you cannot guess when the light will come.
How do I put this code on the micro:bit?
The code is MicroPython. Open the micro:bit Python Editor (python.microbit.org) on a computer, delete the code that is there and paste this one. Connect the board with a USB cable and press Send to micro:bit. If that button does not work, use Save to download the .hex file and copy it to the drive called MICROBIT. You can rebuild the same project with blocks in MakeCode, but this code cannot be pasted there.
Does it work on the older micro:bit (V1) too?
The code is written for the micro:bit V2. Projects that only use the LED display, buttons A and B and the accelerometer also run on a V1. The speaker, the microphone and the touch logo exist only on the V2, so code that uses them gives an error on a V1. If your board has a speaker on the back and a gold logo on the front, it is a V2.
