-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpio2.py
40 lines (33 loc) · 827 Bytes
/
gpio2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import RPi.GPIO as GPIO
import time
import sys
GPIO.setmode(GPIO.BCM)
pin = 17
pin = 27
try: pin = int(sys.argv[1])
except: pass
#GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
#GPIO.setup(25, GPIO.OUT)
print("Initially GPIO.input(%d) ="%pin,GPIO.input(pin))
while 1:
was = GPIO.input(pin)
#print "Pin",pin,"is",was
print(was, end=' ')
sys.stdout.flush()
n = 0
while was == GPIO.input(pin):
n = n+1
print("%7d"%n,was,"\r", end=' ')
# GPIO.output(25,GPIO.LOW)
print()
was = GPIO.input(pin)
#print "Pin",pin,"is",was
print(was, end=' ')
sys.stdout.flush()
n = 0
while was == GPIO.input(pin):
n = n+1
print("%7d"%n,was,"\r", end=' ')
# GPIO.output(25,GPIO.HIGH)
print()