楼主: 驴友花雕
|
[MP动手做] MicroPython动手做(30)——物联网之Blynk |
#MicroPython动手做(30)——物联网之Blynk #Blynk远程控制七彩灯RGB [mw_shl_code=python,false]#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] |
#MicroPython动手做(30)——物联网之Blynk #远程网络八音盒电子琴 [mw_shl_code=python,false]#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] |
6、Blynk远程控制小车前后左右行驶 [mw_shl_code=python,false]#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] |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed