''' Mission 10 - Reaction Tester Medium solution - 2A Use a list of colors and display one on the screen to indicate the start of the reaction timer. This solution also includes the function for intro and countdown. ''' from codex import * import random import time my_colors = [RED, GREEN, BLUE, CYAN, YELLOW, PURPLE, MAGENTA, ORANGE] def wait_button(): while True: if buttons.was_pressed(BTN_A): break # -- add intro function def intro(): display.print("Reaction Tester") display.print("When the screen") display.print("turn a color") display.print("press BTN A") display.print() display.print("Press A to start") wait_button() display.clear() def countdown(): # clear screen and countdown display.clear() 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() # -- call intro intro() while True: display.print("Press Button A") wait_button() 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) color = random.choice(my_colors) display.fill(color) # 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")