from time import sleep
from machine import Pin, PWM
button_A = Pin(28, Pin.IN, Pin.PULL_DOWN)
button_B = Pin(27, Pin.IN, Pin.PULL_DOWN)
led = Pin(2, Pin.OUT)
buzzer = PWM(Pin(1))
buzzer.duty_u16(32767) # Que sea un ciclo de trabajo del 50% (32767/65535)
frequency= 1000
def ButtonIRQHandler (pin):
global frequency
if pin == button_A: # subir la frecuencia
if frequency < 2000:
frequency += 50
led.value(1)
elif pin == button_B: # bajar la frecuencia
if frequency > 100:
frequency -= 50
led.value(0)
# Configure la IRQ y conectela al controlado
button_A.irq (trigger = machine.Pin.IRQ_RISING, handler = ButtonIRQHandler)
button_B.irq (trigger = machine.Pin.IRQ_RISING, handler = ButtonIRQHandler)
while True:
buzzer.freq (frequency)