基于FastLED库
6号引脚输出
#include"FastLED.h"
#define NUM_LEDS 12
#define DATA_PIN 6
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
int value = 5; //起始亮度
int deltaHue = 230; //相邻灯珠色差
//uint8_t max_bright = value;
CRGB leds[NUM_LEDS];
void setup(){
pinMode(DATA_PIN,OUTPUT);
LEDS.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
//FastLED.setBrightness(max_bright);
Serial.begin(115200);
}
void loop(){
for(; value < 50; value++){
FastLED.setBrightness(value);
fill_rainbow(leds, 12, 10, deltaHue);
FastLED.show();
Serial.println(value);
delay(50);
}
for(; value > 5; value--){
FastLED.setBrightness(value);
fill_rainbow(leds, 12, 10, deltaHue);
FastLED.show();
Serial.println(value);
delay(50);
}
delay(100);
}