Created
March 4, 2023 07:55
-
-
Save StephenChamberlain/dfd6523ce80c3f7ee346d636bb2198fc to your computer and use it in GitHub Desktop.
Python script to control LEDs via RaspberryPi
This file contains 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 RPi.GPIO as GPIO | |
import time | |
# --------------------------------- | |
gpioPinRed = 4 | |
gpioPinYellow = 17 | |
gpioPinGreen = 22 | |
delay = 1 | |
def switchPins(red, yellow, green): | |
GPIO.output(gpioPinRed, red) | |
GPIO.output(gpioPinYellow, yellow) | |
GPIO.output(gpioPinGreen, green) | |
# --------------------------------- | |
print("About to activate traffic lights...") | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(gpioPinRed, GPIO.OUT) | |
GPIO.setup(gpioPinYellow, GPIO.OUT) | |
GPIO.setup(gpioPinGreen, GPIO.OUT) | |
# --------------------------------- | |
print("Possible cleanup from earlier runs") | |
switchPins(False, False, False) | |
# --------------------------------- | |
print("Red to green flow") | |
switchPins(True, False, False) | |
time.sleep(delay) | |
switchPins(True, True, False) | |
time.sleep(delay) | |
switchPins(False, False, True) | |
time.sleep(delay) | |
# --------------------------------- | |
print("Cleanup and terminate") | |
switchPins(False, False, False) | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment