6149| 3
|
[高级教程] 当掌控遇上Blynk(6)——语音控制七彩灯 |
本帖最后由 peter3 于 2019-1-5 20:43 编辑 [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 = '990de0dae534455fbc380a626b1f9184'#Blynk授权码 blynk = BlynkLib.Blynk(BLYNK_AUTH)# 初始化Blynk连接 @blynk.VIRTUAL_WRITE(0) def v0_write_handler(value):#从Blnyk的V0管脚获取文本 if value[0]=="绿色。": rgb[0] = (0,255,0) rgb.write() elif value[0]=="红色。": rgb[0] = (255,0,0) rgb.write() elif value[0]=="蓝色。": rgb[0] = (0,0,255) rgb.write() elif value[0]=="关灯。": rgb[0] = (0,0,0) rgb.write() while True: blynk.run()#一直运行blynk pass[/mw_shl_code] |
学习打ka,语音控制彩灯。 手机在用语音输入时会自动加上一个句号。 学习中我用了取前两个字符的方法来实现。 裘老师对blynk的研究真是达到炉火纯青的地步。 [mw_shl_code=python,true]import network,BlynkLib,time from mpython import * wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') wlan.connect('****', '*****') #wifi信息 while not wlan.isconnected(): pass print('network config:', wlan.ifconfig())#输出wifi连接信息 BLYNK_AUTH = '3e55f37b2b34457db86a017425a4****'#Blynk授权码 blynk = BlynkLib.Blynk(BLYNK_AUTH)# 初始化Blynk连接 @blynk.VIRTUAL_WRITE(0) def v0_write_handler(value): text = value[0] buzz.on(400) time.sleep_ms(100) buzz.off() oled.fill(0)#清空OLED上的内容 oled.DispChar(text[0:2], 0, 0)#将收到的文本显示在OLED上 oled.show() if text[0:2] == '红色': rgb.fill((60, 0, 0)) rgb.write() elif text[0:2] == '绿色': rgb.fill((0, 60, 0)) rgb.write() elif text[0:2] == '蓝色': rgb.fill((0, 0, 60)) rgb.write() elif text[0:2] == '关灯': rgb.fill((0, 0, 0)) rgb.write() while True: blynk.run()#一直运行blynk pass [/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed