from machine import Pin
import time
# 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
while True:
input1 = button1.value() # Read button 1 state
input2 = button2.value() # Read button 2 state
if input1 == 0: # Button 1 pressed (LOW)
led1.value(1) # Turn LED 1 ON
else:
led1.value(0) # Turn LED 1 OFF
if input2 == 0: # Button 2 pressed (LOW)
led2.value(1) # Turn LED 2 ON
else:
led2.value(0) # Turn LED 2 OFF
time.sleep(0.01) # Small delay to debounce the buttons (optional)