0

I'm new in micropython and I'm following the book about Raspberry pi pico. And I just wanted to know, how can I just make led ON if button1 or button2 are pressed. Here is my code, and only the first button works, I checked, both buttons are not broken, but the second only shows the value 0 in this code.

from machine import Pin
led = Pin(15, Pin.OUT)
button1 = Pin(14, Pin.IN, Pin.PULL_DOWN)
button2 = Pin(16, Pin.IN, Pin.PULL_DOWN)
while True:
     if button1.value() == 1 or button2.value() == 1:
        led.value(0)
     elif button1.value() == 0 or button2.value() == 1:
         led.value(1)
Derfi
  • 1
  • 1

1 Answers1

0

Try:

while True:
     if button1.value() or button2.value():
        led.value(1)
     else:
        led.value(0)
Markus
  • 5,976
  • 5
  • 6
  • 21