summaryrefslogtreecommitdiff
path: root/recourses/Buzzer.py
diff options
context:
space:
mode:
Diffstat (limited to 'recourses/Buzzer.py')
-rw-r--r--recourses/Buzzer.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/recourses/Buzzer.py b/recourses/Buzzer.py
new file mode 100644
index 0000000..8555184
--- /dev/null
+++ b/recourses/Buzzer.py
@@ -0,0 +1,56 @@
1#!/usr/bin/env python
2
3import RPi.GPIO as GPIO
4import time
5
6# Set #17 as buzzer pin
7BeepPin = 17
8
9def print_message():
10 print("========================================")
11 print ("| Beep |")
12 print ("| ------------------------------ |")
13 print ("| Buzzer connect to GPIO0 |")
14 print ("| |")
15 print ("| Make Buzzer beep |")
16 print ("| |")
17 print ("| |")
18 print ("========================================\n")
19 print 'Program is running...'
20 print 'Please press Ctrl+C to end the program...'
21 raw_input ("Press Enter to begin\n")
22
23def setup():
24 # Set the GPIO modes to BCM Numbering
25 GPIO.setmode(GPIO.BCM)
26 # Set LedPin's mode to output,
27 # and initial level to High(3.3v)
28 GPIO.setup(BeepPin, GPIO.OUT, initial=GPIO.HIGH)
29
30def main():
31 print_message()
32 while True:
33 # Buzzer on (Beep)
34 print 'Buzzer On'
35 GPIO.output(BeepPin, GPIO.LOW)
36 time.sleep(0.1)
37 # Buzzer off
38 print 'Buzzer Off'
39 GPIO.output(BeepPin, GPIO.HIGH)
40 time.sleep(0.1)
41
42def destroy():
43 # Turn off buzzer
44 GPIO.output(BeepPin, GPIO.HIGH)
45 # Release resource
46 GPIO.cleanup()
47
48# If run this script directly, do:
49if __name__ == '__main__':
50 setup()
51 try:
52 main()
53 # When 'Ctrl+C' is pressed, the child program
54 # destroy() will be executed.
55 except KeyboardInterrupt:
56 destroy() \ No newline at end of file