A simple reaction timer in MicroPython on the micro:bit
The micro:bit continues to surprise and delight me. My project yesterday was to write a simple reaction timer in MicroPython . The timer application was really easy to code. I'll build up a subset of the code step-by-step, but the whole program is on GitHub . You can download it here . Here's how the code works: The program starts by displaying a clock image: display.show(Image.CLOCK1) Next, it picks a random time to wait, ranging from 500 ms to 4500 ms. (In other words, it will wait between half a second and four-and-a-half seconds.) sleep(random.randint(500, 4500)) When the time has run out it displays a happy face: display.show(Image.HAPPY) Then it checks every tenth of a second to see if the user has pushed button a (to show they have seen the image, keeping count while it waits. def time(): # returns the time until waiting is over, in 1/10 secs count = 0 while waiting(): sleep(100) # 100 ms = 1/10 secs count = count