# main.py
import mykey
import myservo
from time import sleep
# Codice segreto da inserire
SECRET = ['1', '2', '3', '4']
code = []
buzzer=PWM(Pin(15))
notes=[392,440,392,262,494,392,392,440,392,440,392,294,262,392,392,392,330,262,262,494,440,349,349,330,262,294,262]
print("Pronto. Inserisci codice e premi '#'.")
myservo.chiudi()
while True:
key = mykey.leggi() # Legge un tasto
if key:
print("Premuto:", key)
if key == '#':
# Conferma codice
if code == SECRET:
print("Codice corretto! Apro.")
myservo.apri()
sleep(2)
for freq in notes
#IMPOSTA LA FREQUENZA DEL BUZZER PER SUONARE LA NOTA
buzzer.freq(freq)
#imnposta il volume
buzzer.duty_u16(30000)
sleep(0.3)
buzzer.duty_u16(0)
myservo.chiudi()
else:
print("Codice errato.")
code = [] # Reset sempre dopo '#'
elif key == '*':
# Reset manuale
print("Codice resettato.")
code = []
else:
# Aggiunge il tasto alla sequenza
code.append(key)
print("Codice inserito:", code)
sleep(0.05) # Piccola pausa per evitare cicli troppo veloci