Advertisement
belrey10

Day 4: Expanding Horizons – Multiple LEDs and Buttons

Nov 4th, 2024 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. from machine import Pin
  2. import time
  3.  
  4. # Initialize the LED and button pins
  5. led1 = Pin(16, Pin.OUT)
  6. led2 = Pin(17, Pin.OUT)
  7. button1 = Pin(18, Pin.IN, Pin.PULL_DOWN)
  8. button2 = Pin(19, Pin.IN, Pin.PULL_DOWN)
  9.  
  10.  
  11. while True:
  12.     if button1.value() == 1:
  13.         led1.on()
  14.     else:
  15.         led1.off()
  16.    
  17.     if button2.value() == 1:
  18.         led2.on()
  19.     else:
  20.         led2.off()
  21.    
  22.     time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement