import machine
import time
# Define the GPIO pins for the traffic light LEDs
RED_LED_PIN=1#GP0
YELLOW_LED_PIN=5#GP1
GREEN_LED_PIN=9#GP2
RED_BUTTON_PIN=14#GP14
YELLOW_BUTTON_PIN=17#GP17
GREEN_BUTTON_PIN=21#GP21
#Initialize the GPIO pins for the LEDs
red_led=machine.Pin(RED_LED_PIN,machine.Pin.OUT)
yellow_led_=machine.Pin(YELLOW_LED_PIN,machine.Pin.OUT)
green_led_=machine.Pin(GREEN_LED_PIN,machine.Pin.OUT)
button_red=machine.Pin(RED_BUTTON_PIN,machine.Pin.IN,machine.Pin.PULL_UP)
button_green=machine.Pin(GREEN_BUTTON_PIN,machine.Pin.IN,machine.Pin.PULL_UP)
button_yellow=machine.Pin(YELLOW_BUTTON_PIN,machine.Pin.IN,machine.Pin.PULL_UP)
#Function to turn on the specified LED and turn off the others
def turn_on_led(led_pin):
red_led.value(led_pin==RED_LED_PIN)
yellow_led.value(led_pin==YELLOW_LED_PIN)
green_led.value(led_pin==GREEN_LED_PIN)
#Function to turn on the RED LED
def button_on_red_led(RED_LED_PIN):
while not button_red.value():
turn_on_led(RED_LED_PIN)# Turn on the RED LED
#Function tu turn on the YELLOW LED
def button_on_yellow_led(YELLOW_LED_PIN):
while not button_yellow.value():
turn_on_led(YELLOW_LED_PIN)#Turn on the YELLOW LED
#Function to turn on the GREEN LED
def button_on_green_led(GREEN_LED_PIN):
while not button_green.value():
turn_on_led(GREEN_LED_PIN)#Turn on the GREEN LED
while True:
button_on_red_led(RED_LED_PIN)
button_on_yellow_led(YELLOW_LED_PIN)
button_on_green_led(GREEN_LED_PIN)
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
led1:A
led1:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
led2:A
led2:C
r1:1
r1:2
r2:1
r2:2
led3:A
led3:C
r3:1
r3:2
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r