// 调用Adafruit_NeoPixel模块
#include <Adafruit_NeoPixel.h>
// 设置灯珠数量
#define NUMPIXELS 16
// 设置SPI输出数据引脚
#define PIN_NEOPIXEL 9
// LED引脚设置
#define PIN_LED 18
// 初始化灯珠控制实例
Adafruit_NeoPixel pixels(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
// 当前灯珠指向
int16_t idx = 0;
//初始化将灯珠的等级保存于数组中
int16_t ArraySave[NUMPIXELS][3] = {0};
// 启动设置
void setup() {
// 调试串口速率设置
Serial.begin(115200);
pinMode(PIN_LED, OUTPUT);
// 灯珠控制开始
pixels.begin();
// 设置亮度为255
pixels.setBrightness(255);
// 设置灯珠颜色,全部关闭
pixels.fill(0x000000);
delay(100);
// 设置灯珠颜色
pixels.fill(0xFF0000);
delay(100);
pixels.clear();
int j = 0;
for(j=0;j<NUMPIXELS/3;j++){
pixels.setPixelColor(j,pixels.Color(248-255/(NUMPIXELS/3)*j,255/(NUMPIXELS/3)*j,0));
ArraySave[j][0]=248-255/(NUMPIXELS/3)*j;
ArraySave[j][1]=255/(NUMPIXELS/3)*j;
ArraySave[j][2]=0;
}
for(j=0;j<NUMPIXELS/3;j++){
pixels.setPixelColor(j+8,pixels.Color(0,248-255/(NUMPIXELS/3)*j,255/(NUMPIXELS/3)*j));
ArraySave[j+NUMPIXELS/3][0]=0;
ArraySave[j+NUMPIXELS/3][1]=248-255/(NUMPIXELS/3)*j;
ArraySave[j+NUMPIXELS/3][2]=255/(NUMPIXELS/3)*j;
}
for(j=0;j<NUMPIXELS/3;j++){
pixels.setPixelColor(j+16,pixels.Color(255/(NUMPIXELS/3)*j,0,248-255/(NUMPIXELS/3)*j));
ArraySave[j+NUMPIXELS/3*2][0]=255/(NUMPIXELS/3)*j;
ArraySave[j+NUMPIXELS/3*2][1]=0;
ArraySave[j+NUMPIXELS/3*2][2]=248-255/(NUMPIXELS/3)*j;
}
}
uint16_t c1 = 0;
uint16_t c2 = 0;
uint16_t c3 = 0;
uint16_t sign_bit =0;
uint16_t sign = 1;
// 循环主体程序
void loop(){
uint16_t i = 0,k = 0;
uint16_t t[3] = {0};
for(k=0;k<3;k++){
t[k]=ArraySave[0][k];
}
for(i=0;i<NUMPIXELS;i++){
for(k=0;k<3;k++){
ArraySave[i][k]=ArraySave[i+1][k];
}
pixels.setPixelColor(i,ArraySave[i][0],ArraySave[i][1],ArraySave[i][2]);
}
for(k=0;k<3;k++){
ArraySave[NUMPIXELS-1][k]=t[k];
}
pixels.setPixelColor(NUMPIXELS-1,ArraySave[NUMPIXELS-1][0],ArraySave[NUMPIXELS-1][1],ArraySave[NUMPIXELS-1][2]);
delay(50);
// 显示
pixels.show();
}
Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1