#MicroPython动手做(30)——物联网之Blynk
#远程开关控制板载RGB灯
#MicroPython动手做(30)——物联网之Blynk
#远程开关控制板载RGB灯
from mpython import *
import network
import blynklib
import time
import music
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
blynk = blynklib.Blynk("N14sXx7xQ-rXQF4_gKIFjEQqCC_LzybL", server="116.62.49.166", port=8080)
@blynk.handle_event("connect")
def connect_handler():
print('Blynk connected')
@blynk.handle_event("disconnect")
def connect_handler():
print('Blynk disconnected')
@blynk.handle_event('write V1')
def write_virtual_pin_handler(pin, _value):
global i
for i in range(0, len(_value)):
try: _value[i] = eval(_value[i])
except: pass
if len(_value) == 1: _value = _value[0]
rgb.fill((int(153), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
music.play('G5:1')
@blynk.handle_event('write V0')
def write_virtual_pin_handler(pin, _value):
global i
for i in range(0, len(_value)):
try: _value[i] = eval(_value[i])
except: pass
if len(_value) == 1: _value = _value[0]
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
music.play('E5:1')
oled.fill(0)
oled.DispChar(" 网络已经连接", 0, 16, 1)
oled.show()
rgb[1] = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
music.play('C5:1')
while True:
blynk.run()
|