首页 > 编程语言 >Adafruit CircuitPython NeoPixel All In One

Adafruit CircuitPython NeoPixel All In One

时间:2023-06-02 14:22:27浏览次数:53  
标签:Adafruit LED CircuitPython neopixel NeoPixel https import com pixels

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

image

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_order (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 函数参数的传递方式 ???

匿名参数
具名参数

  1. 具名参数前面的参数可以省略参数名
  2. 具名参数后面的参数必须写参数名
#!/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 and Metro 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)

image

https://www.adafruit.com/product/3403

image

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()

image

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()

(

标签:Adafruit,LED,CircuitPython,neopixel,NeoPixel,https,import,com,pixels
From: https://www.cnblogs.com/xgqfrms/p/17451650.html

相关文章

  • Neopixel组件的应用 -- 梦幻的"七彩灯带"
    项目背景micro:bit的扩展组件中有一个"Neopixel"彩带控件,利用DFROBOT套件中的"七彩灯带",设计一个梦幻的灯带来点亮生活,装饰环境吧编程实践1.材料准备:1张micro:bit开发板,1张DFROBOT扩展板,1根导线,1根七彩灯带2.添加"扩展"组件"Neopixel"(1)点击"扩展"选项(2)选择"Neopixel"组......
  • Python neopixel package bugs All In One
    PythonneopixelpackagebugsAllInOnePython3Pythonneopixellibrarydocshttps://docs.circuitpython.org/projects/neopixel/en/latest/index.htmlhttps://github.com/adafruit/Adafruit_CircuitPython_NeoPixelbugs❌https://github.com/adafruit/Adafruit......
  • 花10几元买ESP32-C3,体验一下MicroPython (和CircuitPython)
    ESP32是近年很火的国产低成本MCU系列。买了芯片ESP32-C3的模组安信可ESP-C3-32S的开发板安信可NodeMCUESP-C3-32S-Kit。开发板很小,没有任何多余的东西,还不如叫它「最......