4136| 1
|
[高级教程] 当掌控遇上Blynk(7)——远程控制台灯 |
本帖最后由 rzyzzxw 于 2019-1-8 12:57 编辑 [mw_shl_code=python,true]import network,BlynkLib,time,music from mpython import * wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') wlan.connect('Maker Space', '20140811') #wifi信息 while not wlan.isconnected(): pass print('network config:', wlan.ifconfig())#输出wifi连接信息 BLYNK_AUTH = '128a4a6cec534cce964160f29e46a64f'#Blynk授权码 blynk = BlynkLib.Blynk(BLYNK_AUTH)# 初始化Blynk连接 @blynk.VIRTUAL_WRITE(0) def v0_write_handler(value):#从Blnyk的V0管脚获取命令 if value[0]=="1": rgb[0] = (255,255,255) #开灯 rgb.write() elif value[0]=="0": rgb[0] = (0,0,0) #关灯 rgb.write() @blynk.VIRTUAL_WRITE(1) def v0_write_handler(value):#从Blnyk的V0管脚获取命令 rgb[0] = (int(value[0]),int(value[0]),int(value[0])) #调节亮度 rgb.write() while True: blynk.run()#一直运行blynk pass[/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed