import time #library that helps us manage time
import random #library that helps us generate random numbers
import board #both board and digitalio help us handle the board,
import digitalio #identifying automatically the pins for us to use.
# Define pin constants
LED_PIN_1 = board.D0
LED_PIN_2 = board.D6
LED_PIN_3 = board.D7
BUTTON_PIN = board.D1
# Initialize LED pins as digital outputs
led_1 = digitalio.DigitalInOut(LED_PIN_1)
led_1.direction = digitalio.Direction.OUTPUT
led_2 = digitalio.DigitalInOut(LED_PIN_2)
led_2.direction = digitalio.Direction.OUTPUT
led_3 = digitalio.DigitalInOut(LED_PIN_3)
led_3.direction = digitalio.Direction.OUTPUT
# Initialize button pin as digital input with pull-up resistor
button = digitalio.DigitalInOut(BUTTON_PIN)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
# Main loop
while True:
# Check if the button is pressed
if not button.value:
# If button is pressed, make all LEDs blink
led_1.value = True
led_2.value = True
led_3.value = True
time.sleep(0.5) # Blink duration
led_1.value = False
led_2.value = False
led_3.value = False
time.sleep(0.5) # Blink duration
else:
# If button is not pressed, continue with the random LED blinking
random_led = random.randint(1, 3)
if random_led == 1:
led_1.value = True
elif random_led == 2:
led_2.value = True
elif random_led == 3:
led_3.value = True
time.sleep(random.uniform(0.1, 1))