Skip to content

Instantly share code, notes, and snippets.

@inderpreet
Created November 24, 2021 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inderpreet/b0018a2f97df7e52538a15b1cd058133 to your computer and use it in GitHub Desktop.
Save inderpreet/b0018a2f97df7e52538a15b1cd058133 to your computer and use it in GitHub Desktop.
#!/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