Created
June 12, 2021 08:14
-
-
Save MattJColes/f79909f229c4be21313ea440bbe2320f to your computer and use it in GitHub Desktop.
Using RPi to control LED traffic lights, iterate through each individually, then flash all twice. Keep loopin!
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 | |
gpio.setmode(gpio.BCM) | |
gpio.setup(5, gpio.OUT) | |
gpio.setup(6, gpio.OUT) | |
gpio.setup(13, gpio.OUT) | |
def main(): | |
try: | |
while True: | |
# iterate through traffic lights then flash | |
gpio.output(5, gpio.HIGH) | |
time.sleep(2) | |
gpio.output(5, gpio.LOW) | |
gpio.output(6, gpio.HIGH) | |
time.sleep(2) | |
gpio.output(6, gpio.LOW) | |
gpio.output(13, gpio.HIGH) | |
time.sleep(2) | |
gpio.output(13, gpio.LOW) | |
time.sleep(1) | |
gpio.output(5, gpio.HIGH) | |
gpio.output(6, gpio.HIGH) | |
gpio.output(13, gpio.HIGH) | |
time.sleep(1) | |
gpio.output(5, gpio.LOW) | |
gpio.output(6, gpio.LOW) | |
gpio.output(13, gpio.LOW) | |
time.sleep(1) | |
gpio.output(5, gpio.HIGH) | |
gpio.output(6, gpio.HIGH) | |
gpio.output(13, gpio.HIGH) | |
time.sleep(1) | |
gpio.output(5, gpio.LOW) | |
gpio.output(6, gpio.LOW) | |
gpio.output(13, gpio.LOW) | |
time.sleep(2) | |
finally: | |
gpio.cleanup() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment