MicroPython动手做(30)——物联网之Blynk-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: eagler8

MicroPython动手做(30)——物联网之Blynk

[复制链接]
 楼主| 发表于 2020-6-9 09:48 | 显示全部楼层
4、Blynk远程控制七彩灯
调整APP控制面板元素为

16.jpg
 楼主| 发表于 2020-6-9 13:25 | 显示全部楼层

#MicroPython动手做(30)——物联网之Blynk
#Blynk远程控制七彩灯RGB


[mw_shl_code=arduino,true]#MicroPython动手做(30)——物联网之Blynk
#Blynk远程控制七彩灯RGB

from mpython import *
import network
import music
import blynklib
import time

my_wifi = wifi()

my_wifi.connectWiFi("zh", "zy1567")

blynk = blynklib.Blynk("CO1NhMoRAYxP3p3hBjvsqrrHmIoYzM0e", 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 V0')
def write_virtual_pin_handler(pin, _value):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    my_list = _value
    rgb.fill( (int(my_list[0]), int(my_list[1]), int(my_list[2])) )
    rgb.write()
    time.sleep_ms(1)


music.play('G5:1')
oled.fill(0)
oled.DispChar("    远程控制七彩灯RGB", 0, 16, 1)
oled.show()
rgb[1] = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
while True:
    blynk.run()[/mw_shl_code]
 楼主| 发表于 2020-6-9 13:37 | 显示全部楼层
mPython X 实验图形编程

17.png
 楼主| 发表于 2020-6-9 15:52 | 显示全部楼层
#MicroPython动手做(30)——物联网之Blynk
#Blynk远程控制七彩灯RGB

https://v.youku.com/v_show/id_XNDcwNTIxNjAzNg==.html



 楼主| 发表于 2020-6-9 16:31 | 显示全部楼层

5、远程网络八音盒电子琴


设置的APP控制面板元素为


18.jpg


 楼主| 发表于 2020-6-9 17:23 | 显示全部楼层
#MicroPython动手做(30)——物联网之Blynk
#远程网络八音盒电子琴

[mw_shl_code=arduino,true]#MicroPython动手做(30)——物联网之Blynk
#远程网络八音盒电子琴

from mpython import *
import network
import blynklib
import time
import music

my_wifi = wifi()

my_wifi.connectWiFi("zh", "zy1567")

blynk = blynklib.Blynk("8d52fd7ed2844892a843158e127ed3f2", 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):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    music.play('C3:2')

@blynk.handle_event('write V2')
def write_virtual_pin_handler(pin, _value):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    music.play('D3:2')

@blynk.handle_event('write V3')
def write_virtual_pin_handler(pin, _value):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    music.play('E3:2')

@blynk.handle_event('write V4')
def write_virtual_pin_handler(pin, _value):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    music.play('F3:2')

@blynk.handle_event('write V5')
def write_virtual_pin_handler(pin, _value):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    music.play('G3:2')

@blynk.handle_event('write V6')
def write_virtual_pin_handler(pin, _value):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    music.play('A3:2')

@blynk.handle_event('write V7')
def write_virtual_pin_handler(pin, _value):
    global my_list
    for i in range(0, len(_value)):
        try: _value = eval(_value)
        except: pass
    if len(_value) == 1: _value = _value[0]
    music.play('B3:2')


oled.fill(0)
oled.DispChar("    远程八音盒电子琴", 0, 16, 1)
oled.show()
rgb[1] = (int(0), int(51), int(0))
rgb.write()
time.sleep_ms(1)
while True:
    blynk.run()[/mw_shl_code]

 楼主| 发表于 2020-6-9 17:26 | 显示全部楼层
mPython X 实验图形编程

19.png
 楼主| 发表于 2020-6-9 17:34 | 显示全部楼层
#MicroPython动手做(30)——物联网之Blynk
#远程网络八音盒电子琴 (实验视频)

https://v.youku.com/v_show/id_XNDcwNTQxMzUxMg==.html



 楼主| 发表于 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]
 楼主| 发表于 2020-6-22 15:52 | 显示全部楼层
设置的APP控制面板的元素为

20.jpg
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-28 00:55 , Processed in 0.090840 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表