|
楼主 |
发表于 2020-6-22 15:49
|
显示全部楼层
6、Blynk远程控制小车前后左右行驶
[mw_shl_code=arduino,true]#MicroPython动手做(30)——物联网之Blynk
#Blynk远程控制小车前后左右行驶
from mpython import *
import network
import blynklib
import music
import time
import parrot
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
blynk = blynklib.Blynk("67988e85a728460fb1d543b9d15e0b5f", server="blynk.mpython.cn", 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):
for i in range(0, len(_value)):
try: _value = eval(_value)
except: pass
if len(_value) == 1: _value = _value[0]
parrot.set_speed(parrot.MOTOR_1, 80)
parrot.set_speed(parrot.MOTOR_2, 80)
@blynk.handle_event('write V2')
def write_virtual_pin_handler(pin, _value):
for i in range(0, len(_value)):
try: _value = eval(_value)
except: pass
if len(_value) == 1: _value = _value[0]
parrot.set_speed(parrot.MOTOR_1, -50)
parrot.set_speed(parrot.MOTOR_2, -50)
@blynk.handle_event('write V3')
def write_virtual_pin_handler(pin, _value):
for i in range(0, len(_value)):
try: _value = eval(_value)
except: pass
if len(_value) == 1: _value = _value[0]
parrot.set_speed(parrot.MOTOR_1, -50)
parrot.set_speed(parrot.MOTOR_2, 50)
@blynk.handle_event('write V4')
def write_virtual_pin_handler(pin, _value):
for i in range(0, len(_value)):
try: _value = eval(_value)
except: pass
if len(_value) == 1: _value = _value[0]
parrot.set_speed(parrot.MOTOR_1, 50)
parrot.set_speed(parrot.MOTOR_2, -50)
@blynk.handle_event('write V5')
def write_virtual_pin_handler(pin, _value):
for i in range(0, len(_value)):
try: _value = eval(_value)
except: pass
if len(_value) == 1: _value = _value[0]
parrot.set_speed(parrot.MOTOR_1, 0)
parrot.set_speed(parrot.MOTOR_2, 0)
oled.fill(0)
oled.DispChar(" 远程控制小车", 0, 1, 1)
oled.show()
music.play('D5:1')
rgb[1] = (int(0), int(51), int(0))
rgb.write()
time.sleep_ms(1)
while True:
blynk.run()[/mw_shl_code]
|
|