[英]Raspberry pi Blynk LED not responding
I am trying to control a LED with Blynk but it doesn't seem to work.我正在尝试用 Blynk 控制 LED,但它似乎不起作用。 I have checked the connections and LED with a simple blinking program, everything works.
我用一个简单的闪烁程序检查了连接和 LED,一切正常。 I run the blynk program, the app successfully connected and I am able to print the status of the button, however, when it comes to the if statement it doesn't work.
我运行 blynk 程序,应用程序已成功连接,并且可以打印按钮的状态,但是,当涉及 if 语句时,它不起作用。
from gpiozero import LED
import blynklib
led = LED(17)
BLYNK_AUTH = '' #insert your Auth Token here
blynk = blynklib.Blynk(BLYNK_AUTH)
while True:
@blynk.handle_event('write V4')
def write_virtual_pin_handler(pin, value):
status = value[0]
print(status)
if status == 1:
led.on()
print("on")
elif status == 0:
led.off()
print("off")
blynk.run()
You have to convert the status
variable into an integer, since the list includes strings, not integers.您必须将
status
变量转换为 integer,因为该列表包含字符串,而不是整数。 In order to do this, change status
to int(status)
in the if / elif statements.为此,请在 if / elif 语句中将
status
更改为int(status)
。
Source: This post I found that documents this behaviour资料来源: 这篇文章我发现记录了这种行为
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.