import time
from machine import Pin
time.sleep(0.1) # Wait for USB to become ready
# Defining the connections to the board
buttonPin = 18
redPin = 0
yellowPin = 5
greenPin = 9
# Defining our devices (LEDs are OUT and Buttons are IN)
button = Pin(buttonPin, machine.Pin.IN, machine.Pin.PULL_UP)
red_led = Pin(redPin, machine.Pin.OUT)
yellow_led = Pin(yellowPin, machine.Pin.OUT)
green_led = Pin(greenPin, machine.Pin.OUT)
# Add code here to run the traffic light if the button is pressed (value = 0)
while True:
# If the button is pressed, run this code
if(button.value() == 0):
# Enter your code to run the traffic light here
red_led.on()
time.sleep(1)
red_led.off()
# Continue the code here
# If the button isn't pressed, run this code
else:
# Enter your code to turn off all the LEDs here
red_led.off()
# Continue the code here