code.py
1 # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 Two-player reaction game example for Pico. LED turns on for between 5 and 10 seconds. Once it 7 turns off, try to press the button faster than the other player to see who wins. 8 9 REQUIRED HARDWARE: 10 * LED on pin GP13. 11 * Button switch on pin GP14. 12 * Button switch on GP16. 13 """ 14 import time 15 import random 16 import board 17 import digitalio 18 19 led = digitalio.DigitalInOut(board.GP13) 20 led.direction = digitalio.Direction.OUTPUT 21 button_one = digitalio.DigitalInOut(board.GP14) 22 button_one.switch_to_input(pull=digitalio.Pull.DOWN) 23 button_two = digitalio.DigitalInOut(board.GP16) 24 button_two.switch_to_input(pull=digitalio.Pull.DOWN) 25 26 led.value = True 27 time.sleep(random.randint(5, 10)) 28 led.value = False 29 while True: 30 if button_one.value: 31 print("Player one wins!") 32 break 33 if button_two.value: 34 print("Player two wins!") 35 break