#include <FastLED.h>        //!< 控制LED灯带的发光,有许多预定义好的发光模式
#include <Button2.h>        //!< 自定义按钮库,包含双击、长按等多种操作

#define LED_PIN     1       //LED连接的digital I/O口为5
#define NUM_LEDS    16       //灯带中LED的数量
#define BRIGHTNESS  255     //初始化亮度255
#define LED_TYPE    WS2812  //LED灯带类型为WS2812
#define COLOR_ORDER GRB     //定义RGB色彩模式

CRGB leds[NUM_LEDS];        //初始化虚拟的LED灯带,灯带由一定数量的LED灯珠组成,可以看作一个整体,实现复杂的光亮模式
bool button_up = true;      //记录按钮按下的状态,true代表按钮松开
CRGB led_palette[10];       //初始化一个数组,用来放置所有10种可以显示在LED灯带上的调色盘颜色模式
int color_index = 0;        //用来记录颜色模式顺序
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32-C3! 2024");
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); //标准语法,初始化一个虚拟LED灯带,定义好它的类型、数量等
  FastLED.setBrightness(BRIGHTNESS); //初始化LED亮度
  led_palette[0] = CRGB::Red; //定义10种调色盘模式,用于显示再LED上
  led_palette[1] = CRGB::Green;
  led_palette[2] = CRGB::Blue;
  led_palette[3] = CRGB::AliceBlue;
  led_palette[4] = CRGB::Aqua;
  led_palette[5] = CRGB::BlueViolet;
  led_palette[6] = CRGB::Chartreuse;
  led_palette[7] = CRGB::DeepPink;
  led_palette[8] = CRGB::FairyLight;
  led_palette[9] = CRGB::MediumTurquoise;
}

void led_loop()
{
   leds[0] = led_palette[color_index]; //将存储好的每一种调色盘的颜色模式赋予LED灯
   leds[1] = led_palette[color_index-1]; //将存储好的每一种调色盘的颜色模式赋予LED灯
  for (int i = 0; i <= NUM_LEDS; i = i + (1)) {
    leds[i] = CRGB::AliceBlue;          // 设置光带中灯珠颜色为绿色,leds[0]为第一个灯珠,leds[1]为第二个灯珠
  }
  FastLED.show();     //标准语法,让虚拟调色盘的颜色模式显示在LED灯珠上
  color_index++;
  if (color_index > 10)
    color_index = 0;
}
void loop() {
  // put your main code here, to run repeatedly:
  delay(1000); // this speeds up the simulation
  //led_loop();
  for (int i = 0; i <= NUM_LEDS; i = i + (1)) {
    leds[i] =led_palette[i];
    leds.show(CRGB(red, green, blue);

  }
  //FastLED.show();

}