from machine import Pin, PWM
from time import sleep
# Initialize pins
button1 = Pin(16, Pin.IN, Pin.PULL_UP) # Button 1 with internal pull-up resistor
button2 = Pin(17, Pin.IN, Pin.PULL_UP) # Button 2 with internal pull-up resistor
led1 = Pin(14, Pin.OUT) # LED 1
led2 = Pin(27, Pin.OUT) # LED 2
led3 = Pin(25, Pin.OUT) # LED 3
buzzer = PWM(Pin(32,Pin.OUT))
buzzer.duty(0) #off buzzer
def buzz(freq,masa):
buzzer.duty(50) #on buzzer
buzzer.freq(freq)
sleep(masa)
buzzer.duty(0) #off buzzer
while True:
input1 = button1.value() # Read button 1 state
input2 = button2.value() # Read button 2 state
if input1 == 0: # Button 1 pressed (LOW)
buzz(300,0.2)
else:
led1.value(0) # Turn LED 1 OFF
if input2 == 0: # Button 2 pressed (LOW)
led1.on() # Turn LED 2 ON
led2.off()
led3.off()
sleep (0.2)
led1.off()
led2.on()
led3.off()
sleep (0.2)
led1.off()
led2.off()
led3.on()
sleep (0.2)
else:
led1.value(0) # Turn LED OFF
led2.value(0)
led3.value(0)
sleep(0.01) # Small delay to debounce the buttons (optional)