MicroPythonneopixle怎么用

本文小編為大家詳細(xì)介紹“MicroPython neopixle怎么用”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“MicroPython neopixle怎么用”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來(lái)學(xué)習(xí)新知識(shí)吧。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、虛擬主機(jī)、營(yíng)銷軟件、網(wǎng)站建設(shè)、陽(yáng)高網(wǎng)站維護(hù)、網(wǎng)站推廣。

microbit/newbit的MicroPython固件中,內(nèi)置了neopixel彩燈的控制,我們可以使用任意一個(gè)GPIO去控制neopixel,支持任意數(shù)量的彩燈。

import neopixel

np = neopixel.NeoPixel(pin1, 8)
np[0] = (0, 0, 200)
np[1] = (0, 50, 100)
np[2] = (200, 0, 0)
np.show()

函數(shù) neopixel.NeoPixel(PIN, NUM) 用來(lái)創(chuàng)建 neopixel 對(duì)象,它有兩個(gè)參數(shù),第一個(gè)是GPIO,第二個(gè)是彩燈的數(shù)量。

neopixel 對(duì)象是一個(gè)元組列表,每個(gè)列表項(xiàng)都是由 RGB 三種顏色組成的元組。RGB參數(shù)的范圍是 0-255,三種顏色組合起來(lái)就有 256 x 256 x 256 = 1.67M種顏色。

顏色參數(shù)寫入列表后并不能改變彩燈,還需要調(diào)用函數(shù) show(),才會(huì)更新。如果要清除彩燈,可以調(diào)用函數(shù) clear().

官方的例子,隨機(jī)顯示彩燈。

"""
    neopixel_random.py

    Repeatedly displays random colours onto the LED strip.
    This example requires a strip of 8 Neopixels (WS2812) connected to pin0.

"""
from microbit import *
import neopixel
from random import randint

# Setup the Neopixel strip on pin0 with a length of 8 pixels
np = neopixel.NeoPixel(pin0, 8)

while True:
    #Iterate over each LED in the strip

    for pixel_id in range(0, len(np)):
        red = randint(0, 60)
        green = randint(0, 60)
        blue = randint(0, 60)

        # Assign the current LED a random red, green and blue value between 0 and 60
        np[pixel_id] = (red, green, blue)

        # Display the current pixel data on the Neopixel strip
        np.show()
        sleep(100)

圖形化編程

對(duì)應(yīng)的mpy代碼:
 

import neopixel
import random
from microbit import *


np = neopixel.NeoPixel(pin0, 8)
while True:
  np[(random.randint(0, 7))] = ((random.randint(1, 50)), (random.randint(1, 50)), (random.randint(1, 50)))
  np.show()
  sleep(100)

如果直接用 microbit/newbit的3.3V供電,注意不要控制太多LED,因?yàn)長(zhǎng)DO的輸出功率有限,很容易造成過(guò)熱保護(hù)。超過(guò)8個(gè)LED最好就用外部電源。

讀到這里,這篇“MicroPython neopixle怎么用”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過(guò)才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

名稱欄目:MicroPythonneopixle怎么用
轉(zhuǎn)載注明:http://muchs.cn/article46/iehphg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、微信小程序、、營(yíng)銷型網(wǎng)站建設(shè)標(biāo)簽優(yōu)化、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)