Created
December 5, 2012 11:12
-
-
Save kurosuke/4214799 to your computer and use it in GitHub Desktop.
Raspberry Pi GPIO(11) INPUT status check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import RPi.GPIO as GPIO | |
# GPIO setup | |
GPIO.setmode(GPIO.BCM) | |
# GPIO11(PIN23) setup for output | |
GPIO.setup(11, GPIO.IN) | |
# default status switch off(False) | |
cur_status = False | |
# push counter | |
push_count = 0 | |
# scan GPIO11 LOW or HI every 0.5sec, | |
# until push 5times | |
while (push_count < 5): | |
status = GPIO.input(11) | |
# check change status | |
if cur_status != status: | |
if status == True: | |
print 'switch on' | |
push_count = push_count + 1 | |
else: | |
print 'switch off' | |
cur_status = status | |
# wait 0.5sec | |
time.sleep(0.5) | |
# GPIO cleanup | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment