本站改版新增arduino频道
#include #define PIN 8 // WS2812 数据引脚连接到 ESP32 的引脚
#define NUMPIXELS 12 // WS2812 LED 的数量
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // 初始化 NeoPixel 库
pixels.show(); // 初始化所有像素为 'off'
}
void showled() {
// 点亮 LED
// 设置所有像素为蓝色
pixels.setPixelColor(0, pixels.Color(255, 255, 255)); // 白色
pixels.show(); // 更新显示
// 等待一段时间
delay(200);
// 关闭 LED
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // 关闭
pixels.show(); // 更新显示
delay(200);
}
void loop() {
// 设置所有像素为红色
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); // 红色
pixels.show(); // 更新显示
delay(50); // 延时 50 毫秒
delay(1000); // 延时 1 秒
// 设置所有像素为绿色
pixels.setPixelColor(0, pixels.Color(0, 255, 0)); // 绿色
pixels.show(); // 更新显示
delay(50); // 延时 50 毫秒
delay(1000); // 延时 1 秒
// 设置所有像素为蓝色
pixels.setPixelColor(0, pixels.Color(0, 0, 255)); // 蓝色
pixels.show(); // 更新显示
delay(50); // 延时 50 毫秒
delay(1000); // 延时 1 秒
// 设置所有像素为蓝色
pixels.setPixelColor(0, pixels.Color(255, 255, 0)); // 黄色
pixels.show(); // 更新显示
delay(50); // 延时 50 毫秒
delay(1000); // 延时 1 秒
// 设置所有像素为蓝色
pixels.setPixelColor(0, pixels.Color(0, 255, 255)); // 青色
pixels.show(); // 更新显示
delay(50); // 延时 50 毫秒
delay(1000); // 延时 1 秒
// 设置所有像素为蓝色
pixels.setPixelColor(0, pixels.Color(255, 0, 255)); // 紫色
pixels.show(); // 更新显示
delay(50); // 延时 50 毫秒
delay(1000); // 延时 1 秒
// 设置所有像素为蓝色
pixels.setPixelColor(0, pixels.Color(255, 255, 255)); // 白色
pixels.show(); // 更新显示
delay(50); // 延时 50 毫秒
delay(1000); // 延时 1 秒
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // 关闭
pixels.show(); // 更新显示
delay(3000);
}
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0098490715026855 seconds