NECO Unit

Neco Unit 是一款独特的 RGB 灯板单元,采用可爱的猫耳造型。它经过精密设计,由 35 颗 WS2812C-2020 RGB 灯珠组成,可提供鲜艳且可自定义的灯光效果。

支持以下产品:

NECOUnit

MicroPython 应用示例

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import *
 9from unit import NECOUnit
10
11
12title0 = None
13i2c0 = None
14neco_0 = None
15
16
17def setup():
18    global title0, i2c0, neco_0
19
20    M5.begin()
21    Widgets.fillScreen(0x222222)
22    title0 = Widgets.Title(
23        "NECOUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
24    )
25
26    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
27    neco_0 = NECOUnit((1, 2), 70, True)
28    neco_0.set_brightness(3)
29
30
31def loop():
32    global title0, i2c0, neco_0
33    M5.update()
34    neco_0.set_random_color_random_led_from(0, 70)
35
36
37if __name__ == "__main__":
38    try:
39        setup()
40        while True:
41            loop()
42    except (Exception, KeyboardInterrupt) as e:
43        try:
44            from utility import print_error_msg
45
46            print_error_msg(e)
47        except ImportError:
48            print("please update to latest firmware")

UiFlow2 应用示例

example.png

neco_cores3_example.m5f2

class NECOUnit

Constructors

class NECOUnit(port, number, active_low)

使用指定端口、LED 数量以及按钮 active low 配置来初始化 NECOUnit。

参数:
  • port (tuple) – 包含端口信息的元组,其中第一个元素用于按钮,第二个元素用于 WS2812 LEDs。

  • number (int) – WS2812 灯带中的 LED 数量。默认值为 70。

  • active_low (bool) – 布尔标志,指示该按钮是否为低电平有效。默认为 True。

UiFlow2

init.png

Methods

NECOUnit.set_color_from(begin, end, rgb, per_delay)

为从起始索引到结束索引范围内的 LED 设置指定颜色。

参数:
  • begin (int) – 起始 LED 索引。

  • end (int) – 结束 LED 索引。

  • rgb (int) – 要设置的颜色,采用 RGB 格式。

  • per_delay (int) – 设置每个 LED 颜色之间的延迟(毫秒)。默认值为 0。

UiFlow2

set_color_from.png

NECOUnit.set_color_saturation_from(begin, end, rgb, per_delay)

为从起始索引到结束索引范围内的 LED 设置指定颜色及饱和度。

参数:
  • begin (int) – 起始 LED 索引。

  • end (int) – 结束 LED 索引。

  • rgb (int) – RGB 格式的基础颜色。

  • per_delay (int) – 设置每个 LED 颜色之间的延迟(毫秒)。默认值为 0。

NECOUnit.color_saturation(rgb, saturation)

调整 RGB 颜色的饱和度。

参数:
  • rgb (int) – RGB 格式的基础颜色。

  • saturation (float) – 期望的饱和度级别(0 到 100)。

返回:

调整饱和度后的新颜色,采用 RGB 格式。

NECOUnit.set_color_running_from(begin, end, rgb, per_delay)

为从起始索引到结束索引范围内的 LED 设置颜色,然后逐个清除它们,从而创建跑马效果。

参数:
  • begin (int) – 起始 LED 索引。

  • end (int) – 结束 LED 索引。

  • rgb (int) – 要设置的颜色,采用 RGB 格式。

  • per_delay (int) – 设置并清除每个 LED 颜色之间的延迟时间,单位为毫秒。默认值为 0。

UiFlow2

set_color_running_from.png

NECOUnit.set_random_color_random_led_from(begin, end)

在指定范围内以随机顺序为每个 LED 设置随机颜色。

参数:
  • begin (int) – 起始 LED 索引。

  • end (int) – 结束 LED 索引。

UiFlow2

set_random_color_random_led_from.png

NECOUnit.fill(v)

使用指定颜色填充整个 NECOUnit 灯带。

参数:

v (int) – 一个包含 RGB(或 RGBW)值的元组,用于填充灯带。

NECOUnit.set_color(i, c)

设置指定索引处 LED 的颜色。

参数:
  • i – 要设置的 LED 索引。

  • c (int) – 要将 LED 设置为的颜色值(RGB 或 RGBW 格式)。

UiFlow2

set_color.png

NECOUnit.fill_color(c)

使用指定颜色填充整个 NECOUnit 灯带。

参数:

c (int) – 用于填充灯带的颜色值(RGB 或 RGBW 格式)。

UiFlow2

fill_color.png

NECOUnit.set_brightness(br)

为 NECOUnit 灯带设置亮度。

参数:

br (int) – 亮度级别(百分比,0-100)。

UiFlow2

set_brightness.png