#include <FastLED.h>
#include <EncButton.h>
#include <EEPROM.h>
Button butn_up(12);
#define PIN 13
#define NUM_LEDS 144
#define BRIGHTNESS 120
#define SPEED 50
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
TBlendType currentBlending;
byte PROGRAMM = 0;
void setup() {
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
pinMode(13, OUTPUT);
EEPROM.get(0, PROGRAMM);
if (PROGRAMM > 2) PROGRAMM = 0;
}
void loop()
{
butn_up.tick();
if (butn_up.click()) {
if (++PROGRAMM > 2) PROGRAMM = 0;
EEPROM.put(0, PROGRAMM);
}
switch (PROGRAMM) {
case 0: dynamic_rainbow(); break;
case 1: static_rainbow(); break;
case 2: thriller(); break;
}
}
void thriller()
{
static unsigned long start_millis = millis();
if (butn_up.click()) start_millis = millis();
byte timer = 5;
byte hue;
if (millis()-start_millis < timer*1000) {
hue = 0;
} else {
hue = 160;
}
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue, 255, BRIGHTNESS);
}
FastLED.show();
}
void static_rainbow()
{
static byte counter;
for (int i = 0; i < NUM_LEDS; i++ ) { // от 0 до первой трети
leds[i] = CHSV(counter, 255, BRIGHTNESS); // HSV. Увеличивать HUE (цвет)
// умножение i уменьшает шаг радуги
}
counter++; // counter меняется от 0 до 255 (тип данных byte)
FastLED.show();
delay(SPEED); // скорость движения радуги
}
void dynamic_rainbow()
{
static byte counter;
for (int i = 0; i < NUM_LEDS; i++ ) { // от 0 до первой трети
leds[i] = CHSV(counter + i, 255, BRIGHTNESS); // HSV. Увеличивать HUE (цвет)
// умножение i уменьшает шаг радуги
currentBlending = LINEARBLEND;
}
counter++; // counter меняется от 0 до 255 (тип данных byte)
FastLED.show();
delay(SPEED); // скорость движения радуги
}