#include <FastLED.h>
#define LED_PIN 14
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];
int fadeValue = 0;
int cr = 255;
int cg = 255;
int cb = 255;
bool ledOn = false;
int btnPin = 12;
void setup() {
Serial.begin(115200);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.clear();
pinMode(btnPin, INPUT_PULLUP);
}
void loop() {
uint8_t state = digitalRead(btnPin);
Serial.println((state));
if (digitalRead(btnPin) == LOW ){
ledOn = true;
fadeValue = 255;
delay(200);
}
if (ledOn) {
if (fadeValue > 0) {
// leds[0].setRGB(fadeValue, fadeValue, fadeValue);
for (int i = 1; i < 16; i += 2) {
leds[i].setRGB(cr-i*10, cg-i*20, cb-i*30);
}
fadeValue -= 5; // Adjust this value to change fade speed
} else {
ledOn = false;
for(int i=0;i<16;i++)
leds[i].setRGB(0, 0, 0);
}
}
FastLED.show();
delay(20);
}