From 0cff38f0670107ee47b1237bdd5504f299977ebd Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 23 Dec 2015 22:23:41 +0100 Subject: [PATCH] print button events on pin 14 --- button.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 button.py diff --git a/button.py b/button.py new file mode 100644 index 0000000..2218af1 --- /dev/null +++ b/button.py @@ -0,0 +1,20 @@ +#!/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()