-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_passiveBuzzer.py
More file actions
executable file
·37 lines (29 loc) · 874 Bytes
/
03_passiveBuzzer.py
File metadata and controls
executable file
·37 lines (29 loc) · 874 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
30
31
32
33
34
35
#!/usr/bin/env python
#-----------------------------------------------------------
# File name : 03_passiveBuzzer.py
# Description : make a passive buzzer beep.
# Author : Jason
# E-mail : jason@adeept.com
# Website : www.adeept.com
# Date : 2015/06/12
#-----------------------------------------------------------
import RPi.GPIO as GPIO
import time
BZRPin = 12
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
GPIO.setup(BZRPin, GPIO.OUT) # Set pin mode as output
GPIO.output(BZRPin, GPIO.LOW)
p = GPIO.PWM(BZRPin, 50) # init frequency: 50HZ
p.start(50) # Duty cycle: 50%
try:
while True:
for f in range(100, 2000, 100):
p.ChangeFrequency(f)
time.sleep(0.2)
for f in range(2000, 100, -100):
p.ChangeFrequency(f)
time.sleep(0.2)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()