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)
2
  • Please write down a small matrix which led value has to be set on which button value and share it with us! Commented Aug 20, 2022 at 7:31
  • Sorry, I don't understand @Markus Commented Aug 20, 2022 at 8:20

1 Answer 1

0

Try:

while True:
     if button1.value() or button2.value():
        led.value(1)
     else:
        led.value(0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.