from machine import Pin, PWM
import math
import time
# Uso della costante matematica pi greco
PI = math.pi
# Configurazione del pulsante con pull-down
button = Pin(14, Pin.IN, Pin.PULL_DOWN)
# Configurazione del pin del buzzer
pinB = Pin(23, Pin.OUT)
passiveBuzzer = PWM(pinB, freq=2000)
passiveBuzzer.duty(0) # Inizialmente il buzzer è spento
led1 = Pin(4, Pin.OUT) # LED Rosso
led2 = Pin(2, Pin.OUT) # LED Giallo
led3 = Pin(5, Pin.OUT) # LED Verde
led1.off()
led2.off()
led3.off()
while True:
if not button.value(): # Se il pulsante NON è premuto
for x in range(0, 36): # Loop per 36 iterazioni
sinVal = math.sin(x * 10 * PI / 180)
toneVal = 2000 + int(sinVal * 500) # Calcola la frequenza del tono
passiveBuzzer.freq(toneVal)
passiveBuzzer.duty(512)
ledfreq=toneVal/10.0
print ledfreq
'''if(ledfreq<20)
led1.on()
if(ledfreq>20)
led2.on()
if(ledfreq>40)
led3.on()
time.sleep_ms(10)'''
passiveBuzzer.duty(0)
led1.off()
led2.off()
led3.off()
sleep(3)