|
楼主 |
发表于 2020-6-4 16:49
|
显示全部楼层
4、使用A\B按键来开关Yeelight灯泡
[mw_shl_code=python,true]# MicroPython动手做(28)——物联网之Yeelight
#使用A\B按键来开关Yeelight灯泡
from mpython import *
import network
import time
from yeelight import *
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
def on_button_a_down(_):
global i
time.sleep_ms(10)
if button_a.value() == 1: return
rgb.fill((int(153), int(153), int(153)))
rgb.write()
time.sleep_ms(1)
time.sleep_ms(500)
LED.turn_on()
time.sleep_ms(500)
LED.set_rgb(255, 255, 255)
def on_button_b_down(_):
global i
time.sleep_ms(10)
if button_b.value() == 1: return
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
time.sleep_ms(500)
LED.turn_off()
button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)
button_b.irq(trigger=Pin.IRQ_FALLING, handler=on_button_b_down)
rgb[1] = (int(51), int(51), int(255))
rgb.write()
time.sleep_ms(1)
if len(discover_bulbs()) > 0:
LED = Bulb(discover_bulbs()[0]["ip"])[/mw_shl_code]
|
|