from codex import * import random import time count = 0 delay = 1.0 def wait_button(): global going, count, button while True: if buttons.was_pressed(BTN_A): button = "A" break if buttons.was_pressed(BTN_B): button = "B" break def display_info(count): display.clear() display.draw_text("Press A for Orange", scale=2, color=WHITE, x=6, y=40) display.draw_text("Press B for Purple", scale=2, color=WHITE, x=6, y=80) display.draw_text("Correct: " + str(count), scale=3, color=CYAN, x=6, y=120) def intro(): pixels.set([BLACK, BLACK, BLACK, BLACK]) display.clear() display.draw_text("Test your color", scale=2, color=WHITE, x=6, y=40) display.draw_text("and quickness", scale=2, color=WHITE, x=6, y=80) time.sleep(2) display.clear() display.draw_text("After the light goes off", scale=1, color=CYAN, x=6, y=40) display.draw_text(" A for Orange", scale=2, color=WHITE, x=6, y=80) display.draw_text(" B for Purple", scale=2, color=WHITE, x=6, y=120) time.sleep(1) display.clear() def set_random(color): global delay index = random.randint(0, 3) if color == 1: pixels.set(index, ORANGE) else: pixels.set(index, PURPLE) time.sleep(delay) pixels.set([BLACK, BLACK, BLACK, BLACK]) if delay >= 0.2: delay = delay - 0.1 def looping(): global count, going color = random.randint(1, 2) set_random(color) wait_button() if button == "A" and color == 1: count = count + 1 elif button == "B" and color == 2: count = count + 1 else: going = False display_info(count) time.sleep(1) display.show("To play, press A") wait_button() intro() going = True while going: looping() display.clear() display.draw_text("Correct: " + str(count), scale=3, color=PINK, x=5, y=80)