This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
Pi/button.py

21 lines
409 B
Python
Raw Normal View History

2015-12-23 21:23:41 +00:00
#!/usr/bin/python
from time import sleep
import RPi.GPIO as GPIO
try:
GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP)
last_state = True
while True:
input_state = GPIO.input(14)
if input_state == False and input_state != last_state:
print 'Button pressed'
last_state = input_state
sleep(0.2)
finally:
GPIO.cleanup()