-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactiveBuzzer.py
30 lines (24 loc) · 891 Bytes
/
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
import RPi.GPIO as GPIO
import time
BeepPin = 12 # pin12
def setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
GPIO.setup(BeepPin, GPIO.OUT) # Set pins 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 KeyboardInterupt: # When 'CTRL+C' is pressed, the child program destroy() will be execture.
destroy()