Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
LED_G = 16
LED_Y = 20
LED_R = 21
PBT1 = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_G, GPIO.OUT)
GPIO.setup(LED_Y, GPIO.OUT)
GPIO.setup(LED_R, GPIO.OUT)
GPIO.setup(PBT1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
state = 0 # variable to store LED State
try:
while True:
# wait here till pushbutton is pressed
while( not GPIO.input(PBT1) ):
time.sleep(0.1)
while( GPIO.input(PBT1) ):
time.sleep(0.1)
GPIO.output(LED_G, 0)
GPIO.output(LED_R, 0)
GPIO.output(LED_Y, 0)
if(state == 0):
GPIO.output(LED_G, 1)
elif(state == 1):
GPIO.output(LED_Y, 1)
else:
GPIO.output(LED_R, 1)
state = state + 1
if(state >=3):
state = 0
except KeyboardInterrupt:
print("Ctrl+C Detected")
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment