Created
July 7, 2025 17:26
-
-
Save simonprickett/fa6ffc704be7110543cb816818e54a41 to your computer and use it in GitHub Desktop.
CircuitPython Trafflc Lights 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 board | |
import digitalio | |
import time | |
# Setup. | |
red = digitalio.DigitalInOut(board.GP4) | |
red.direction = digitalio.Direction.OUTPUT | |
amber = digitalio.DigitalInOut(board.GP3) | |
amber.direction = digitalio.Direction.OUTPUT | |
green = digitalio.DigitalInOut(board.GP5) | |
green.direction = digitalio.Direction.OUTPUT | |
# Begin by making sure all the LEDs are off. | |
red.value = False | |
amber.value = False | |
green.value = False | |
while True: | |
# Red. | |
red.value = True | |
time.sleep(3) | |
# Red and amber. | |
amber.value = True | |
time.sleep(1) | |
# Green. | |
red.value = False | |
amber.value = False | |
green.value = True | |
time.sleep(5) | |
# Amber. | |
green.value = False | |
amber.value = True | |
time.sleep(2) | |
# Amber off (red comes on at top of loop). | |
amber.value = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment