Skip to content

Instantly share code, notes, and snippets.

@Indavelopers
Created June 5, 2017 11:47
Show Gist options
  • Save Indavelopers/d4e45ab805edec81369e1736e4b16088 to your computer and use it in GitHub Desktop.
Save Indavelopers/d4e45ab805edec81369e1736e4b16088 to your computer and use it in GitHub Desktop.
Detectar cambios de estado del botón
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
PIN_BUTTON = 16
GPIO.setup(PIN_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(PIN_BUTTON, GPIO.RISING)
for _ in range(10):
if GPIO.event_detected(channel):
print('Button pressed')
break
time.sleep(1)
else:
print('Button was not pressed')
print('Exiting execution: cleanning GPIO setup')
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment