-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path02_activeBuzzer.py
executable file
·43 lines (33 loc) · 1.1 KB
/
02_activeBuzzer.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
#!/usr/bin/env python
#-----------------------------------------------------------
# File name : 02_activeBuzzer.py
# Description : make an active buzzer beep.
# Author : Jason
# E-mail : [email protected]
# Website : www.adeept.com
# Date : 2015/06/12
#-----------------------------------------------------------
import RPi.GPIO as GPIO
import time
BeepPin = 12 # pin11
def setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
GPIO.setup(BeepPin, GPIO.OUT) # Set pin mode as output
GPIO.output(BeepPin, GPIO.HIGH) # Set pin to high(+3.3V) to off the beep
def loop():
while True:
GPIO.output(BeepPin, GPIO.LOW)
time.sleep(0.1)
GPIO.output(BeepPin, GPIO.HIGH)
time.sleep(0.1)
def destroy():
GPIO.output(BeepPin, GPIO.HIGH) # beep off
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
print 'Press Ctrl+C to end the program...'
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()