Skip to content

Instantly share code, notes, and snippets.

@simonprickett
Created July 7, 2025 17:24
Show Gist options
  • Save simonprickett/17dfc46c0ee8d497ef1bd228a606608b to your computer and use it in GitHub Desktop.
Save simonprickett/17dfc46c0ee8d497ef1bd228a606608b to your computer and use it in GitHub Desktop.
Traffic Lights MicroPython Script
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