-
Notifications
You must be signed in to change notification settings - Fork 0
/
buzzer.py
38 lines (32 loc) · 833 Bytes
/
buzzer.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
#-----------------------------------------------------------------------------#
# Buzzer control with Pulse Width Modulation
#
# Micropython code for Raspberry Pi Pico w
#
# File : buzzer.py
# Source : https://github.com/RPiSpy/pi-pico
#
# Desc : Sound a buzzer using PWM
# Hardware : Pi Pico or Pi Pico W
# Buzzer (passive type with "+" pin)
# Software : n/a
#
# Author : Matt Hawkins
# Website : https://www.raspberrypi-spy.co.uk/
#-----------------------------------------------------------------------------#
import time
from machine import Pin,PWM
# Create PWM object
buzzer = PWM(Pin(15))
# Set frequency
buzzer.freq(500)
# Sound tone
buzzer.duty_u16(5000)
time.sleep(0.5)
buzzer.duty_u16(0)
# Wait 0.5 seconds
time.sleep(0.5)
# Sound tone
buzzer.duty_u16(20000)
time.sleep(0.5)
buzzer.duty_u16(0)