from adafruit_circuitplayground import cp import time import pulseio import digitalio import adafruit_irremote import board from adafruit_debouncer import Button pulsein = pulseio.PulseIn(board.A3, maxlen=120, idle_state=True) decoder = adafruit_irremote.GenericDecode() button = Button(lambda: cp.button_a) hits = 0 three_hits = 0 zombie = 0 regen = 1 heals = (255, 0, 93, 162) bpress = 1 RED = (255, 0, 0) YELLOW = (255, 150, 0) GREEN = (0, 255, 0) CYAN = (0, 255, 255) BLUE = (0, 0, 255) PURPLE = (180, 0, 255) WHITE = (255, 255, 255) OFF = (0, 0, 0) cp.pixels.brightness = 0.3 def color_chase(color, wait): for i in range(10): cp.pixels[i] = color time.sleep(wait) time.sleep(0.02) def flash_hit(color): color_chase(RED, .02) color_chase(OFF, .02) color_chase(color, .02) cp.play_file("examples_dip.wav") def flash(color): cp.pixels.fill(OFF) time.sleep(.3) cp.pixels.fill(color) time.sleep(.3) cp.pixels.fill(OFF) time.sleep(.3) cp.pixels.fill(color) time.sleep(.3) cp.play_file("examples_rise.wav") cp.pixels.fill(GREEN) while True: button.update() pulses = decoder.read_pulses(pulsein, blocking=False) if button.rose: print("Button A pressed!") if bpress < 3: bpress = bpress +1 else: bpress = 1 elif button.fell: print("No More Button!") try: if pulses != None: received_code = decoder.decode_bits(pulses) print("NEC Infrared code received: ", received_code) if received_code == heals: flash(GREEN) hits = 0 else: if pulses and bpress ==1: if hits < 2: flash_hit(GREEN) hits = hits + 1 else: flash_hit(RED) if pulses and bpress ==2: if hits < 0: flash_hit(PURPLE) hits = hits + 1 elif hits < 2: flash_hit(PURPLE) hits = hits + 1 else: flash_hit(RED) if pulses and bpress ==3: flash_hit(RED) except adafruit_irremote.IRNECRepeatException: continue except adafruit_irremote.IRDecodeException as e: continue