''' Mission 10 - Reaction Tester Mild solution - 1A Create and call a function for the countdown ''' from codex import * import random import time def wait_button(): while True: if buttons.was_pressed(BTN_A): break # -- add countdown function def countdown(): # 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() # --- MAIN LOOP --- while True: display.print("Press Button A") wait_button() # call countdown function countdown() # get random delay time ms = random.randrange(1000, 5000) delay_time = ms / 1000 time.sleep(delay_time) # turn pixels GREEN buttons.was_pressed(BTN_A) pixels.set([GREEN, GREEN, GREEN, GREEN]) audio.pitch(600, 0.5) # 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")