from machine import Pin
import time
# Define pin numbers for LEDs and buttons
led1 = Pin(2, Pin.OUT) # LED 1
led2 = Pin(3, Pin.OUT) # LED 2
button1 = Pin(4, Pin.IN, Pin.PULL_UP) # Button for LED 1
button2 = Pin(5, Pin.IN, Pin.PULL_UP) # Button for LED 2
def check_buttons():
if not button1.value(): # Button 1 is pressed
led1.value(1) # Turn on LED 1
else:
led1.value(0) # Turn off LED 1
if not button2.value(): # Button 2 is pressed
led2.value(1) # Turn on LED 2
else:
led2.value(0) # Turn off LED 2
while True:
check_buttons() # Check the status of buttons and control LEDs
time.sleep(0.1) # Small delay to debounce button presses