知識(shí)點(diǎn):什么是掌控板?
掌控板是一塊普及STEAM創(chuàng)客教育、人工智能教育、機(jī)器人編程教育的開(kāi)源智能硬件。它集成ESP-32高性能雙核芯片,支持WiFi和藍(lán)牙雙模通信,可作為物聯(lián)網(wǎng)節(jié)點(diǎn),實(shí)現(xiàn)物聯(lián)網(wǎng)應(yīng)用。同時(shí)掌控板上集成了OLED顯示屏、RGB燈、加速度計(jì)、麥克風(fēng)、光線(xiàn)傳感器、蜂鳴器、按鍵開(kāi)關(guān)、觸摸開(kāi)關(guān)、金手指外部拓展接口,支持圖形化及MicroPython代碼編程,可實(shí)現(xiàn)智能機(jī)器人、創(chuàng)客智造作品等智能控制類(lèi)應(yīng)用。
1、物聯(lián)網(wǎng)(Internet of Things,縮寫(xiě):IoT)
是基于互聯(lián)網(wǎng)、傳統(tǒng)電信網(wǎng)等信息承載體,讓所有能行使獨(dú)立功能的普通物體實(shí)現(xiàn)互聯(lián)互通的網(wǎng)絡(luò)。其應(yīng)用領(lǐng)域主要包括運(yùn)輸和物流、工業(yè)制造、健康醫(yī)療、智能環(huán)境(家庭、辦公、工廠(chǎng))等,具有十分廣闊的市場(chǎng)前景。
物聯(lián)網(wǎng)的概念最早是在1999年由Kevin Ashton在一次演講中提出來(lái)的,當(dāng)時(shí)他是一個(gè)RFID研究機(jī)構(gòu)的執(zhí)行主任,這家研究機(jī)構(gòu)是在寶潔公司和吉列公司的贊助下成立的。而他本人也因此被稱(chēng)為物聯(lián)網(wǎng)之父。隨后麻省理工學(xué)院的Neil Gershenfeld教授出版了一本名為《When things Start to Think》的書(shū)。以這些為標(biāo)志,正式揭開(kāi)了物聯(lián)網(wǎng)的序幕。
物聯(lián)網(wǎng)的英文是Internet of Things,縮寫(xiě)為IoT。這里的“物”指的是我身邊一切能與網(wǎng)絡(luò)聯(lián)通的物品。例如你帶的手表、你騎的共享單車(chē)、馬路上的汽車(chē)、家里的冰箱、路邊的路燈、甚至是一棵樹(shù)。只要一件物品能夠與網(wǎng)絡(luò)相連,它就都是物聯(lián)網(wǎng)中的“物”。而所謂物聯(lián)網(wǎng),就是“物”與人,以及“物”與“物”之間,通過(guò)網(wǎng)絡(luò)來(lái)傳遞和處理信息。
Yeelight
是全球領(lǐng)先的智能照明品牌,2014年加入小米智能家居生態(tài)鏈,在物聯(lián)網(wǎng)、智能交互、工業(yè)設(shè)計(jì)和燈光體驗(yàn)等方面不斷打磨,持續(xù)定義照明行業(yè)的最高標(biāo)準(zhǔn)。Yeelight擁有完整的智能家居照明產(chǎn)品線(xiàn),產(chǎn)品系列輻射家裝照明、臺(tái)上照明、氛圍照明以及智能照明控制,全球累計(jì)出貨1100余萬(wàn)件,用戶(hù)輻射100多個(gè)國(guó)家和地區(qū),致力于通過(guò)高品質(zhì)光環(huán)境的打造,讓更多人享受到智能照明的便捷和樂(lè)趣。
9、RGB顏色模型
Yeelight使用"RGB" 和"HSV" 兩種顏色模型來(lái)設(shè)置燈泡燈光的顏色。
RGB色彩模式由自然界中光的三原色的混合原理發(fā)展而來(lái)。RGB分別代表紅色(Red)、綠色(Green)、藍(lán)色(Blue)。它的每個(gè)象素在每種顏色上可以負(fù)載2的8次方(256)種亮度級(jí)別,這樣三種顏色通道合在一起就可以產(chǎn)生256的3次方(1670多萬(wàn))種顏色,它在理論上可以還原自然界中存在的任何顏色。
RGB模式的圖像支持多個(gè)圖層。據(jù)有R、G、B三個(gè)單色通道和一個(gè)由它們混合顏色的彩色通道。
在RGB色彩模式的圖像中,某種顏色的含量越多,那么這種顏色的亮度也越高,由其產(chǎn)生的結(jié)果中這種顏色也就越亮。例如如果三種顏色的亮度級(jí)別都為0(亮度級(jí)別最低),則它們混合出來(lái)的顏色就是黑色;如果它們的亮度級(jí)別都為255(亮度級(jí)別最高),則其結(jié)果為白色。這和自然界中光的三原色的混合原理相同。
RGB色彩模式是運(yùn)用最廣泛的色彩模式之一,它能適應(yīng)多種輸出的需要,并能較完整地還原圖像的顏色信息。如大多數(shù)的顯示屏、RGB打印、多種寫(xiě)真輸出設(shè)備都需要用RGB色彩模式的圖像來(lái)輸出。
10、六個(gè)觸摸鍵控制的RGB顏色燈
#MicroPython動(dòng)手做(28)——物聯(lián)網(wǎng)之Yeelight
#六個(gè)觸摸鍵控制的RGB顏色燈
# MicroPython動(dòng)手做(28)——物聯(lián)網(wǎng)之Yeelight
#六個(gè)觸摸鍵控制的RGB顏色燈
from mpython import *
import network
import time
import music
from yeelight import *
from machine import Timer
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
_status_p = _status_y = _status_t = _status_h = _status_o = _status_n = 0
def on_touchpad_P_pressed():pass
def on_touchpad_P_unpressed():pass
def on_touchpad_Y_pressed():pass
def on_touchpad_Y_unpressed():pass
def on_touchpad_T_pressed():pass
def on_touchpad_T_unpressed():pass
def on_touchpad_H_pressed():pass
def on_touchpad_H_unpressed():pass
def on_touchpad_O_pressed():pass
def on_touchpad_O_unpressed():pass
def on_touchpad_N_pressed():pass
def on_touchpad_N_unpressed():pass
tim12 = Timer(12)
def timer12_tick(_):
global _status_p, _status_y, _status_t, _status_h, _status_o, _status_n
try:
touchPad_P.read();pass
except:
return
if touchPad_P.read() < 400:
if 1 != _status_p:_status_p = 1;on_touchpad_P_pressed()
elif 0 != _status_p:_status_p = 0;on_touchpad_P_unpressed()
if touchPad_Y.read() < 400:
if 1 != _status_y:_status_y = 1;on_touchpad_Y_pressed()
elif 0 != _status_y:_status_y = 0;on_touchpad_Y_unpressed()
if touchPad_T.read() < 400:
if 1 != _status_t:_status_t = 1;on_touchpad_T_pressed()
elif 0 != _status_t:_status_t = 0;on_touchpad_T_unpressed()
if touchPad_H.read() < 400:
if 1 != _status_h:_status_h = 1;on_touchpad_H_pressed()
elif 0 != _status_h:_status_h = 0;on_touchpad_H_unpressed()
if touchPad_O.read() < 400:
if 1 != _status_o:_status_o = 1;on_touchpad_O_pressed()
elif 0 != _status_o:_status_o = 0;on_touchpad_O_unpressed()
if touchPad_N.read() < 400:
if 1 != _status_n:_status_n = 1;on_touchpad_N_pressed()
elif 0 != _status_n:_status_n = 0;on_touchpad_N_unpressed()
tim12.init(period=100, mode=Timer.PERIODIC, callback=timer12_tick)
def on_touchpad_P_pressed():
global i
time.sleep_ms(500)
bulb.set_rgb(153, 0, 0)
oled.DispChar("P鍵 紅色", 38, 32, 1)
oled.show()
rgb.fill((int(153), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
def on_touchpad_Y_pressed():
global i
time.sleep_ms(500)
bulb.set_rgb(0, 153, 0)
oled.DispChar("Y鍵 綠色", 38, 32, 1)
oled.show()
rgb.fill((int(0), int(153), int(0)))
rgb.write()
time.sleep_ms(1)
def on_touchpad_T_pressed():
global i
time.sleep_ms(500)
bulb.set_rgb(51, 51, 255)
oled.DispChar("T鍵 藍(lán)色", 38, 32, 1)
oled.show()
rgb.fill((int(51), int(51), int(255)))
rgb.write()
time.sleep_ms(1)
def on_touchpad_H_pressed():
global i
time.sleep_ms(500)
bulb.set_rgb(255, 102, 0)
oled.DispChar("H鍵 橙色", 38, 32, 1)
oled.show()
rgb.fill((int(153), int(51), int(0)))
rgb.write()
time.sleep_ms(1)
def on_touchpad_O_pressed():
global i
time.sleep_ms(500)
bulb.set_rgb(204, 51, 204)
oled.DispChar("O鍵 紫色", 38, 32, 1)
oled.show()
rgb.fill((int(102), int(51), int(102)))
rgb.write()
time.sleep_ms(1)
def on_touchpad_N_pressed():
global i
time.sleep_ms(500)
bulb.set_rgb(255, 204, 51)
oled.DispChar("N鍵 黃色", 38, 32, 1)
oled.show()
rgb.fill((int(153), int(102), int(51)))
rgb.write()
time.sleep_ms(1)
rgb[1] = (int(51), int(51), int(51))
rgb.write()
time.sleep_ms(1)
music.play('G5:1')
bulb = Bulb(discover_bulbs()[0]["ip"])
time.sleep_ms(500)
bulb.turn_on()
oled.fill(0)
oled.DispChar("觸摸鍵控制RGB燈", 18, 16, 1)
oled.show()
mPython X 實(shí)驗(yàn)圖形編程
#MicroPython動(dòng)手做(28)——物聯(lián)網(wǎng)之Yeelight
#六個(gè)觸摸鍵控制的RGB顏色燈(實(shí)驗(yàn)視頻)
https://v.youku.com/v_show/id_XNDcwMTY3MzkxNg==.html?spm=a2h0c.8166622.PhoneSokuUgc_1.dtitle
11、隨機(jī)顏色的RGB模型彩虹燈
命令消息配額限制為line 243(到限額會(huì)自動(dòng)停止運(yùn)行)
#MicroPython動(dòng)手做(28)——物聯(lián)網(wǎng)之Yeelight
#隨機(jī)顏色的RGB模型彩虹燈
# MicroPython動(dòng)手做(28)——物聯(lián)網(wǎng)之Yeelight
#隨機(jī)顏色的RGB模型彩虹燈
from mpython import *
import network
from yeelight import *
import time
import music
import random
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
random.seed(time.ticks_cpu())
bulb = Bulb(discover_bulbs()[0]["ip"])
time.sleep_ms(500)
bulb.turn_on()
oled.fill(0)
oled.DispChar("RGB彩虹燈", 33, 16, 1)
oled.DispChar(discover_bulbs()[0]['ip'], 15, 28, 1)
oled.show()
music.play('G5:1')
time.sleep_ms(500)
bulb.set_rgb(0, 153, 0)
rgb.fill((int(0), int(102), int(0)))
rgb.write()
time.sleep_ms(1)
while True:
time.sleep_ms(500)
bulb.set_rgb(0, (random.randint(1, 255)),(random.randint(1, 255)))
time.sleep_ms(500)
bulb.set_rgb((random.randint(1, 255)), 0,(random.randint(1, 255)))
time.sleep_ms(500)
bulb.set_rgb((random.randint(1, 255)), (random.randint(1, 255)),0)
mPython X 實(shí)驗(yàn)圖形編程
#MicroPython動(dòng)手做(28)——物聯(lián)網(wǎng)之Yeelight
#隨機(jī)顏色的RGB模型彩虹燈(實(shí)驗(yàn)視頻)
https://v.youku.com/v_show/id_XNDcwMTgxOTQwOA==.html?spm=a2h0c.8166622.PhoneSokuUgc_1.dtitle文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-623942.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-623942.html
到了這里,關(guān)于【雕爺學(xué)編程】MicroPython動(dòng)手做(28)——物聯(lián)網(wǎng)之Yeelight 3的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!