-
Notifications
You must be signed in to change notification settings - Fork 0
/
wemos_buzzer.py
40 lines (33 loc) · 946 Bytes
/
wemos_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
39
40
import os,machine,math,time
from machine import ADC, I2C, Pin
class Buzzer():
# 262 294 330 349 392 440 494
def __init__(self):
self.queue = []
self.isPause = False
def play(self,freq=300,delay=0.1):
pin25 = machine.PWM(machine.Pin(12), duty=512)
pin25.freq(freq)
time.sleep(delay)
machine.PWM(machine.Pin(12), duty=0)
def playList(self,list):
self.queue.extend(list)
def pause(self,b):
self.isPause = b
def stop(self):
self.queue = []
def run(self):
while True:
if len(self.queue)>0 and not self.isPause:
note = self.queue[0]
del self.queue[0]
self.play(note[0],note[1])
buzzer = Buzzer()
buzzer.play(262,0.15)
buzzer.play(294,0.1)
buzzer.play(330,0.1)
buzzer.play(349,0.1)
buzzer.play(392,0.1)
buzzer.play(440,0.1)
buzzer.play(494,0.1)
buzzer.play(0,0.1)