#Traffic light LEDs using an array from machine import Pin import time # Define GPIO pins for the LEDs RED = Pin(2, Pin.OUT) AMBER = Pin(6, Pin.OUT) GREEN = Pin(10, Pin.OUT) # Put them in an array lights = [RED, AMBER, GREEN] #################################################### # visual Thonny breakout. #use this declaration for Pico1W & Pico2W #use this declaration for Pico 1W and Pico 2W OBLED = Pin('LEDW',Pin.OUT) # Print a message in Thonny to remind user to break out of code now. print('booting... Press ctrl-c to stop') # loop 20 times for i in range (20): #for Pico1W and Pico2W use this # turn on LED, wait half a second. OBLED.on() time.sleep(0.5) # turn off LED, wait half a second. OBLED.off() time.sleep(0.5) #################################################### # Helper function to turn all lights off def all_off(): for light in lights: light.off() while True: # Red all_off() RED.on() time.sleep(3) # Red + Amber AMBER.on() time.sleep(1) # Green all_off() GREEN.on() time.sleep(3) # Amber all_off() AMBER.on() time.sleep(1)