简体   繁体   中英

Raspberry pi Blynk LED not responding

I am trying to control a LED with Blynk but it doesn't seem to work. I have checked the connections and LED with a simple blinking program, everything works. 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.

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. In order to do this, change status to int(status) in the if / elif statements.

Source: This post I found that documents this behaviour

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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