3856| 2
|
[高级教程] 当掌控遇上Blynk(4)——远程电子琴 |
本帖最后由 rzyzzxw 于 2019-1-8 21:05 编辑 [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 = '5b93d9b73235451d9b37a365643d46f9'#Blynk授权码 blynk = BlynkLib.Blynk(BLYNK_AUTH)# 初始化Blynk连接 @blynk.VIRTUAL_WRITE(1) def v1_write_handler(value):#从Blnyk的V1管脚获取DO的信号 if value[0]=='1': music.pitch(523, 300) @blynk.VIRTUAL_WRITE(2) def v2_write_handler(value):#从Blnyk的V2管脚获取RE的信号 if value[0]=='1': music.pitch(587, 300) @blynk.VIRTUAL_WRITE(3) def v3_write_handler(value):#从Blnyk的V3管脚获取MI的信号 if value[0]=='1': music.pitch(659, 300) @blynk.VIRTUAL_WRITE(4) def v4_write_handler(value):#从Blnyk的V4管脚获取FA的信号 if value[0]=='1': music.pitch(698, 300) @blynk.VIRTUAL_WRITE(5) def v5_write_handler(value):#从Blnyk的V5管脚获取SO的信号 if value[0]=='1': music.pitch(784, 300) @blynk.VIRTUAL_WRITE(6) def v6_write_handler(value):#从Blnyk的V6管脚获取LA的信号 if value[0]=='1': music.pitch(880, 300) @blynk.VIRTUAL_WRITE(7) def v7_write_handler(value):#从Blnyk的V7管脚获取XI的信号 if value[0]=='1': music.pitch(987, 300) while True: blynk.run()#一直运行blynk pass[/mw_shl_code] |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed