/****************************************************
code obtained using chatgpt by arvind patil date 7 may 2023
/****************************************************
Once you have saved the code to your MicroPython editor, you can transfer it
to the Pico board using a file transfer protocol such as AMPY.
Here are the steps to upload the code using AMPY:
Connect your Pico board to your computer using a USB cable.
Open a command prompt or terminal window and navigate
thhe directory where you saved the traffic_light.py file.
Use the following command to transfer the file to the Pico board:
ampy --port [PORT] put traffic_light.py
Replace [PORT] with the name of the serial port that your
Pico board is connected to. You
************************************************************/
import machine
import utime
# Define the pins for each LED
red_pin = machine.Pin(0, machine.Pin.OUT)
yellow_pin = machine.Pin(1, machine.Pin.OUT)
green_pin = machine.Pin(2, machine.Pin.OUT)
# Define functions to turn on each LED
def turn_on_red():
red_pin.value(1)
yellow_pin.value(0)
green_pin.value(0)
def turn_on_yellow():
red_pin.value(0)
yellow_pin.value(1)
green_pin.value(0)
def turn_on_green():
red_pin.value(0)
yellow_pin.value(0)
green_pin.value(1)
# Main loop to cycle through the red, yellow, and green lights
while True:
turn_on_red()
utime.sleep(5)
turn_on_yellow()
utime.sleep(2)
turn_on_green()
utime.sleep(5)
turn_on_yellow()
utime.sleep(2)