#include <FastLED.h>
#define COLORBTN 8
#define MODEBTN 9
#define ACTIVATEBTN 10
#define LED_PIN 6
#define LED_COUNT 30
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 60
CRGB leds[LED_COUNT];
uint32_t color;
uint32_t colors[] = {CRGB::Blue,
CRGB::Red,
CRGB::Cyan,
CRGB::Green,
CRGB::HotPink,
CRGB::Indigo,
CRGB::DarkSlateGrey,
CRGB::Yellow, };
int numOfColors = 8;
int colorNum =0;
#define FASTMODE 0
#define SLOWMODE 1
int mode = 0;
bool active = false;
void setup() {
pinMode(COLORBTN, INPUT_PULLUP);
pinMode(MODEBTN, INPUT_PULLUP);
pinMode(ACTIVATEBTN, INPUT_PULLUP);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
color = colors[colorNum];
}
void loop() {
if(!digitalRead(COLORBTN)){
delay(250);
ColorSwitch();
}
if(!digitalRead(MODEBTN))
mode = FASTMODE;
else
mode = SLOWMODE;
if(!digitalRead(ACTIVATEBTN))
{
delay(250);
if(!active){
fill_solid(leds,LED_COUNT,CRGB::Black);
FastLED.show();
FastLED.setBrightness(0);
for (int i = 0; i < LED_COUNT; i++)
{
leds[i] = color;
FastLED.setBrightness(255 * i/(LED_COUNT-1));
FastLED.show();
delay((mode==FASTMODE) ? 5 : 80);
}
active = true;
}
else{
for (int i = LED_COUNT - 1; i >= 0; i--)
{
leds[i] = CRGB::Black;
FastLED.setBrightness(255 * i/(LED_COUNT-1));
FastLED.show();
delay((mode == FASTMODE) ? 5 : 80);
}
active = false;
}
}
}
void ColorSwitch(){
color = colors[colorNum];
colorNum++;
if(colorNum == numOfColors)
colorNum=0;
}