-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_timer555.py
More file actions
executable file
·30 lines (22 loc) · 723 Bytes
/
09_timer555.py
File metadata and controls
executable file
·30 lines (22 loc) · 723 Bytes
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
#!/usr/bin/env python
import RPi.GPIO as GPIO
SigPin = 11 # pin11
g_count = 0
def count(ev=None):
global g_count
g_count += 1
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(SigPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set Pin's mode is input, and pull up to high level(3.3V)
GPIO.add_event_detect(SigPin, GPIO.RISING, callback=count) # wait for rasing
def loop():
while True:
print 'g_count = %d' % g_count
def destroy():
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()