from machine import Pin, PWM
import time
key = Pin(27, Pin.IN, Pin.PULL_DOWN)
num = 0
beep = PWM(Pin(2), freq = 1, duty = 128)
Do = 523
Re = 587
Mi = 659
Fa = 698
Sol = 784
La = 880
Si = 988
Do1 = 1046
def play(freq, duty_time):
beep.freq(freq)
beep.duty(128)
time.sleep(duty_time)
beep.duty(0)
time.sleep(0.05)
duty_time = 0.8
while True:
if key.value() == 1:
time.sleep_ms(100)
if key.value() == 1:
num += 1
print(num)
if num == 1:
play(Do, duty_time)
elif num == 2:
play(Re, duty_time)
elif num == 3:
play(Mi, duty_time)
elif num == 4:
play(Fa, duty_time)
elif num == 5:
play(Sol, duty_time)
elif num == 6:
play(La, duty_time)
elif num == 7:
play(Si, duty_time)
else:
play(Do1, duty_time)
num = 0