Skip to content

Instantly share code, notes, and snippets.

@inderpreet
Created November 24, 2021 01:07
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/1dc576ac20c1cef59c53d2ec0a803b2f to your computer and use it in GitHub Desktop.
Save inderpreet/1dc576ac20c1cef59c53d2ec0a803b2f to your computer and use it in GitHub Desktop.
etec224 button with 3 leds code
#!/usr/bin/python3
import RPi.GPIO as GPIO
from time import sleep
LED_G = 21
BUTTON = 17
PRESSED = 0
RELEASED = 1
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_G, GPIO.OUT)
GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while True:
button_state = GPIO.input(BUTTON) # Read the button
if button_state == RELEASED: # CHECK if pressed
i = 12 # set counter to 5
state = 1 # set value of state
while i>0: # Loop
if GPIO.input(BUTTON)== PRESSED:
break
GPIO.output(LED_G, state) # swtich the LED
state = not state # invert the state
i = i - 1 # decrement count
sleep(0.01) # Sleep and repeat
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