简体   繁体   English

第二个按钮不起作用 Raspberry pi pico

[英]Second button is not working Raspberry pi pico

I'm new in micropython and I'm following the book about Raspberry pi pico.我是 micropython 的新手,我正在关注关于 Raspberry pi pico 的书。 And I just wanted to know, how can I just make led ON if button1 or button2 are pressed.我只是想知道,如果按下按钮 1 或按钮 2,我怎样才能使 LED 亮起。 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.这是我的代码,只有第一个按钮有效,我检查了,两个按钮都没有损坏,但第二个仅显示此代码中的值 0。

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)

Try:尝试:

while True:
     if button1.value() or button2.value():
        led.value(1)
     else:
        led.value(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM