Adafruit CircuitPython NeoPixel All In One
Raspberry Pi
& Python &WS2812B
RGB LED Strip
neopixel
# install for current user
$ pip3 install adafruit-circuitpython-neopixel
# install system-wide
$ sudo pip3 install adafruit-circuitpython-neopixel
https://pypi.org/project/adafruit-circuitpython-neopixel/
https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel
docs
https://readthedocs.org/projects/adafruit-circuitpython-neopixel/
https://docs.circuitpython.org/projects/neopixel/en/latest/
https://docs.circuitpython.org/projects/neopixel/en/latest/index.html
https://docs.circuitpython.org/projects/neopixel/en/3.1.1/_modules/neopixel.html
API
neopixel.GRB= 'GRB'
Green Red Blue
neopixel.GRBW= 'GRBW'
Green Red Blue White
Class:
neopixel.NeoPixel(pin: Pin, n: int, *, bpp: int = 3, brightness: float = 1.0, auto_write: bool = True, pixel_order: str = None)
A sequence of neopixels.
Parameters:
pin
(Pin) – The pin to output neopixel data on.
n
(int) – The number of neopixels in the chain
bpp
(int) – Bytes per pixel. 3
for RGB and 4
for RGBW pixels.
brightness
(float) – Brightness of the pixels between 0.0 and 1.0 where 1.0 is full brightness
auto_write
(bool) – True if the neopixels should immediately change when set. If False, show must be called explicitly.
pixel_orde
r (str) – Set the pixel color channel order. GRBW is set by default.
https://docs.circuitpython.org/projects/neopixel/en/latest/api.html
#!/usr/bin/env python3
# coding: utf8
import neopixel
import board
from time import sleep
# neopixel.NeoPixel(pin: Pin, n: int, *, bpp: int = 3, brightness: float = 1.0, auto_write: bool = True, pixel_order: str = None)
# pixels = neopixel.NeoPixel(board.D18, 60, brightness=0.2, auto_write: False, pixel_order: neopixel.GRB)
pixels = neopixel.NeoPixel(board.D18, 60, brightness=0.2, auto_write: True, pixel_order: neopixel.GRB)
#!/usr/bin/env python3
# coding: utf8
import neopixel
import board
from time import sleep
# neopixel.NeoPixel(pin: Pin, n: int, *, bpp: int = 3, brightness: float = 1.0, auto_write: bool = True, pixel_order: str = None)
pixels = neopixel.NeoPixelboard.NEOPIXEL, 60, brightness=0.2, auto_write: False, pixel_order: neopixel.GRB)
pixels = neopixel.NeoPixel(board.NEOPIXEL, 60, brightness=0.2, auto_write: True, pixel_order: neopixel.GRB)
Python 函数参数的传递方式 ???
匿名参数
具名参数
- 具名参数前面的参数可以省略参数名
- 具名参数后面的参数必须写参数名
#!/usr/bin/env python3
# coding: utf8
def func_args(arg1: int, arg2: str = None, arg3: float = 1.0, arg4: bool = True):
print("arg1 {}".format(arg1))
print("arg2 {}".format(arg2))
print("arg3 {}".format(arg3))
print("arg4 {}".format(arg4))
# 全部使用匿名参数 ✅
func_args(60, "LEDs", 0.2, False)
# 全部使用匿名参数 ✅
func_args(arg1: 60, arg2: "LEDs", arg3: 0.2, arg4: ,False)
# 混合使用,前面匿名参数,后面具名参数 ✅
func_args(60, "LEDs", arg3: 0.2, arg4: False)
# 混合使用,前面匿名参数,中间具名参数,后面匿名参数 ❌
func_args(60, "LEDs", arg3: 0.2, False)
Python online REPL
https://www.runoob.com/try/runcode.php?filename=HelloWorld&type=python3
bugs ❌
https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/issues/151
https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/issues/153
demos
Feather M0 Express
andMetro M0 Express
#!/usr/bin/env python3
# coding: utf8
import board
import neopixel
# 1 LEDs ❓
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixels[0] = (10, 0, 0)
https://www.adafruit.com/product/3403
https://www.adafruit.com/product/3505
Circuit Playground Express
#!/usr/bin/env python3
# coding: utf8
import board
import neopixel
# 10 LEDs❓
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)
pixels[0] = (10, 0, 0)
pixels[9] = (0, 10, 0)
pixels.show()
https://www.adafruit.com/product/3333
#!/usr/bin/env python3
# coding: utf8
import board
import neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)
# RGB test
pixels[0] = (255, 0, 0)
pixels[1] = (0, 255, 0)
pixels[2] = (0, 0, 255)
pixels.show()
(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
rpi_ws281x
from rpi_ws281x import PixelStrip, Color, ws
PixelStrip
Color
#!/usr/bin/env python3
# coding: utf8
import time
import argparse
from rpi_ws281x import PixelStrip, Color, ws
# from rpi_ws281x import *
# LED strip configuration
LED_COUNT = 60 # Number of LED pixels.
LED_PIN = 18 # BCM GPIO pin connected to the pixels (18 uses `PWM`).
# LED_PIN = 10 # GPIO pin connected to the pixels (10 uses `SPI` /dev/spidev0.0).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) # ❓ 不同 LED 频率不同,5050 LED ❓
LED_DMA = 10 # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
#LED_STRIP = ws.WS2812B_STRIP
LED_STRIP = ws.SK6812_STRIP_GRB
# ...
https://github.com/rpi-ws281x/rpi-ws281x-python
API docs ?
https://github.com/rpi-ws281x/rpi-ws281x-python/blob/master/library/rpi_ws281x.py#L72-L88
https://github.com/rpi-ws281x/rpi-ws281x-python/tree/master/examples
https://github.com/rpi-ws281x/rpi-ws281x-python/blob/master/examples/neopixelclock.py#L48
refs
RPi.GPIO
https://www.cnblogs.com/xgqfrms/p/17374377.html
rpi_ws281x
https://www.cnblogs.com/xgqfrms/p/17387711.html
WS2811_STRIP_GRB
color channel:
GRB
=> WS2811_STRIP_GRB(RGB LEDs Strip, 3参数)
GRBW => WS2811_STRIP_GRBW
(RGBW LEDs Strip, 4 参数)
https://www.cnblogs.com/xgqfrms/p/17394537.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!