Created
July 7, 2025 17:24
-
-
Save simonprickett/17dfc46c0ee8d497ef1bd228a606608b to your computer and use it in GitHub Desktop.
Traffic Lights MicroPython Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import machine | |
import time | |
# Setup. | |
red = machine.Pin(4, machine.Pin.OUT) | |
amber = machine.Pin(3, machine.Pin.OUT) | |
green = machine.Pin(5, machine.Pin.OUT) | |
# Begin by making sure all the LEDs are off. | |
red.low() | |
amber.low() | |
green.low() | |
while True: | |
# Red. | |
red.high() | |
time.sleep(3) | |
# Red and amber. | |
amber.high() | |
time.sleep(1) | |
# Green. | |
red.low() | |
amber.low() | |
green.high() | |
time.sleep(5) | |
# Amber. | |
green.low() | |
amber.high() | |
time.sleep(2) | |
# Amber off (red comes on at top of loop). | |
amber.low() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment