8 个 Neopixel/WS2812B LED 的测试代码

此测试代码以循环颜色切换 8 个 WS2812b LED,并测试每个 LED 中的所有三个 R/G/B LED 及其连接。它基于带有 74LV245 电平转换器的 ESP32,但它也适用于 NeoPixelBus 支持的其他平台。在我的配置中,3.3V 信号输出引脚在引脚 13 上。

example-2.cpp
#include <NeoPixelAnimator.h>

const uint16_t PixelCount = 8;
const uint8_t PixelPin = 13;

NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);

void DrawPixels(uint32_t offset)
{
    strip.SetPixelColor((0 + offset) % 8, RgbColor(255, 0, 0));
    strip.SetPixelColor((1 + offset) % 8, RgbColor(0, 255, 0));
    strip.SetPixelColor((2 + offset) % 8, RgbColor(0, 0, 255));
    strip.SetPixelColor((3 + offset) % 8, RgbColor(255, 255, 0));
    strip.SetPixelColor((4 + offset) % 8, RgbColor(0, 255, 255));
    strip.SetPixelColor((5 + offset) % 8, RgbColor(255, 0, 255));
    strip.SetPixelColor((6 + offset) % 8, RgbColor(255, 255, 255));
    strip.SetPixelColor((7 + offset) % 8, RgbColor(0, 0, 0));
    strip.Show();
}

void setup()
{
    strip.Begin();
    strip.Show();
}

uint32_t loopCounter = 0;
void loop()
{
  DrawPixels(loopCounter);
  loopCounter++;
  delay(250);
}

PlatformIO 配置:

example-1.ini
;
;   构建选项:构建标志、源过滤器
;   上传选项:自定义上传端口、速度和额外标志
;   库选项:依赖项、额外库存储
;   高级选项:额外脚本
;
; 请访问文档了解其他选项和示例
; https://docs.platformio.org/page/projectconf.html

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino
lib_deps =
     makuna/NeoPixelBus @ ^2.6.9

Check out similar posts by category: Electronics, ESP8266/ESP32, PlatformIO