''' Mission 10 - Reaction Tester The program uses the computer clock to calculate the reaction time. After the pixels are lit, the player is timed on how long it takes to press a button. Concepts learned: using the computer clock (sleep, ticks_ms and ticks_diff) clearing the screen and turning pixels off using a list to turn on all pixels with a single command writing a function to ''' from codex import * import random import time def wait_button(): while True: if buttons.was_pressed(BTN_A): break while True: display.print("Press Button A") wait_button() # clear screen and countdown display.clear() pixels.set([BLACK, BLACK, BLACK, BLACK]) display.print("3", scale=6) time.sleep(1) display.print("2", scale=6) time.sleep(1) display.print("1", scale=6) time.sleep(1) display.clear() # get random delay time my_number = random.randrange(100, 500) delay_time = ms / 1000 time.sleep(delay_time) # turn pixels GREEN buttons.was_pressed(BTN_A) pixels.set([GREEN, GREEN, GREEN, GREEN]) # get start and end time start_time = time.ticks_ms() wait_button() end_time = time.ticks_ms() reaction_time = time.ticks_diff(end_time, start_time) display.print("Reaction Time:") display.print(reaction_time) display.print("milliseconds")