#include <FastLED.h>
#define NUM_LEDS 182
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
int potpin0 = 0; // analog pin used to connect the potentiometer
int val_0; // variable to read the value from the analog pin
int potpin1 = 1; // analog pin used to connect the potentiometer
int val_1; // variable to read the value from the analog pin
int potpin2 = 2; // 4analog pin used to connect the potentiometer
int val_2; // variable to read the value from the analog pin
int potpin3 = 3; // analog pin used to connect the potentiometer
int val_3; // variable to read the value from the analog pin
int potpin4 = 4; // analog pin used to connect the potentiometer
int val_4; // variable to read the value from the analog pin
int potpin5 = 5; // analog pin used to connect the potentiometer
int val_5; // variable to read the value from the analog pin
int potpin6 = 6; // analog pin used to connect the potentiometer
int val_6; // variable to read the value from the analog pin
uint16_t val_6_2; // variable to read the value from the analog pin
int stop = 0;
int rstop = 0;
void setup() {
delay(100); // power-up safety delay
FastLED.addLeds<WS2813, DATA_PIN, GRB>(leds, NUM_LEDS);
Serial.begin(9600); // Delete production
}
void loop() {
// FastLED.clear();
// // Turn the LED on, then pause
// leds[0] = CRGB::Red;
// FastLED.show();
// delay(500);
// // Now turn the LED off, then pause
// leds[0] = CRGB::Black;
// FastLED.show();
// delay(500);
// refresh_step(val_1);
// FastLED.setBrightness(val_0);
// FastLED.showColor(CRGB(val_3,val_4,val_5), 1-10);
// delay(100);
// changeColorFill(); // 1 (1-10) Быстрая смена цвета всех диодов с регулировкой яркостью
// changeColor(); // 2 (10-20) Cмена цвета всех диодов с заданной скоростью и регулировкой яркостью
// rainbow(); // 3 (20-30) Функция радуга с заданной скоростью и регулировкой яркости
// rainbowCycle(); // 4 (30-40) Функция радуга по кругу с заданной скоростью и регулировкой яркости
// theaterChaseRainbow(); // 5 (40-50) Функция радуга с эффектом бегущей строки с заданной скоростью и регулировкой яркости
// bimLed(); // 6 (50-60) Функция белый бегунок на цветовой палитре заданной по DMX
// strobe(); // 7 (60-70) Функция стробоскопа
// rainbow_center(); // 8 (70-80) Радуга из центра
// center(); // 9 (80-90) Функция бегущий цвет от центра
// int i = center(rstop);
// rstop = i;
// center_end(); // 10 (90-100) Функция бегущий цвет от центра до края и обратно
// flag(); // 11 (100-255) Функция флага РБ
}
// Функция стробоскопа
void strobe() {
stop = 0;
stop = refresh_step(val_1);
if (stop==10) {
return;
}
FastLED.setBrightness(val_0);
FastLED.showColor(CRGB(val_3,val_4,val_5));
delay(2*val_2);
FastLED.setBrightness(val_6);
FastLED.showColor(CRGB(val_3,val_4,val_5));
delay(2*val_2);
}
// Функция бегущий цвет от центра
int center(int s) {
stop = 0;
int start = 0;
int end = 256;
int r = rand() % (end - start + 1) + start;
if (r == 0) {
start = 100;
}
int g = rand() % (end - start + 1) + start;
start = 0;
int b = rand() % (end - start + 1) + start;
int r2 = rand() % (end - start + 1) + start;
if (r2 == 0) {
start = 100;
}
int g2 = rand() % (end - start + 1) + start;
start = 0;
int b2 = rand() % (end - start + 1) + start;
int start2 = 0;
int end2 = 50;
rstop = 0;
int leds_rand = rand() % (end2 - start2 + 1) + start2;
refresh_step(val_1);
for(int i = (NUM_LEDS/2); i >= leds_rand; i--) {
val_f0();
val_f2();
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
if (s < i) {
leds_off(s);
}
leds_on(i, r2, g2, b2);
int l = NUM_LEDS-i-1;
s = s + 1;
int s2 = NUM_LEDS - s;
if (s2 > l) {
leds_off(s2);
}
leds_on(l, r2, g2, b2);
FastLED.setBrightness(val_0);
FastLED.show();
val_f1();
delay(0.25*val_2);
rstop = i;
}
return rstop;
}
// Функция бегущий цвет от центра до края и обратно
void center_end() {
stop = 0;
stop = refresh_step(val_1);
int start = 50;
int end = 256;
int r = rand() % (end - start + 1) + start;
if (r == 0) {
start = 100;
}
int g = rand() % (end - start + 1) + start;
start = 0;
int b = rand() % (end - start + 1) + start;
val_f1();
for(int i = (NUM_LEDS/2); i >= 0; i--) {
val_f0();
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
val_f2();
leds_on(i, r, g, b);
int l = NUM_LEDS - i;
leds_on(l, r, g, b);
FastLED.setBrightness(val_0);
FastLED.show();
delay(val_2/4);
}
val_f1();
for(int i = (NUM_LEDS/2); i >= 0; i--) {
val_f0();
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
val_f2();
leds_off(i);
int l = NUM_LEDS - i;
leds_off(l);
FastLED.setBrightness(val_0);
FastLED.show();
delay(val_2/4);
}
val_f1();
for(int i = 0; i <= (NUM_LEDS/2); i++) {
val_f0();
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
val_f2();
leds_on(i, r, g, b);
int l = NUM_LEDS - i;
leds_on(l, r, g, b);
FastLED.show();
val_f1();
delay(val_2/4);
}
val_f1();
for(int i = 0; i <= (NUM_LEDS/2); i++) {
val_f0();
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
val_f2();
leds_off(i);
int l = NUM_LEDS - i;
leds_off(l);
FastLED.show();
val_f1();
delay(val_2/4);
}
}
void leds_on(int i, int r, int g, int b) {
leds[i] = CRGB(r,g,b);
}
void leds_off(int i) {
leds[i] = CRGB(0,0,0);
}
// Функция флага РБ
void flag() {
uint16_t numPixelsFlag = NUM_LEDS/3;
stop = 0;
stop = refresh_step(val_1);
int speed = 1.5*val_2;
for(uint16_t i=0; i<numPixelsFlag; i++) {
val_f0();
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
FastLED.setBrightness(val_0);
leds[i] = CRGB(0,255,0);
FastLED.show();
}
for(uint16_t i=numPixelsFlag; i<NUM_LEDS; i++) {
val_f0();
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
FastLED.setBrightness(val_0);
leds[i] = CRGB(255,0,0);
FastLED.show();
}
stop = val_f1_res(val_1);
if (stop==10) {
return;
}
delay(100);
}
int refresh_step(int val_1_pref) {
val_0 = analogRead(potpin0);
val_0 = map(val_0, 0, 1023, 0, 255);
val_1 = analogRead(potpin1);
val_1 = map(val_1, 0, 1023, 0, 255);
val_2 = analogRead(potpin2);
val_2 = map(val_2, 0, 1023, 0, 255);
val_3 = analogRead(potpin3);
val_3 = map(val_3, 0, 1023, 0, 255);
val_4 = analogRead(potpin4);
val_4 = map(val_4, 0, 1023, 0, 255);
val_5 = analogRead(potpin5);
val_5 = map(val_5, 0, 1023, 0, 255);
val_6 = analogRead(potpin6);
val_6 = map(val_6, 0, 1023, 0, 255);
Serial.print("Val_0: "); // Delete production
Serial.print(val_0); // Delete production
Serial.print("; Prog: "); // Delete production
Serial.print(val_1); // Delete production
Serial.print("; Speed: "); // Delete production
Serial.print(val_2); // Delete production
Serial.print("; R: "); // Delete production
Serial.print(val_3); // Delete production
Serial.print("; G: "); // Delete production
Serial.print(val_4); // Delete production
Serial.print("; B: "); // Delete production
Serial.print(val_5); // Delete production
Serial.print("; Option: "); // Delete production
Serial.println(val_6); // Delete production
if (val_1_pref != val_1) {
return 10;
} else {
return 0;
}
}
void val_f0() {
val_0 = analogRead(potpin0);
val_0 = map(val_0, 0, 1023, 0, 255);
}
void val_f1() {
val_1 = analogRead(potpin1);
val_1 = map(val_1, 0, 1023, 0, 255);
}
int val_f1_res(int val_1_pref) {
val_1 = analogRead(potpin1);
val_1 = map(val_1, 0, 1023, 0, 255);
// Serial.println(val_1_pref);
// Serial.println(val_1);
// delay(600);
if (val_1_pref != val_1) {
// Serial.println("Stop!!!"); // Delete production
FastLED.clear();
return 10;
} else {
return 0;
}
}
void val_f2() {
val_2 = analogRead(potpin2);
val_2 = map(val_2, 0, 1023, 0, 255);
}
void val_f3() {
val_3 = analogRead(potpin3);
val_3 = map(val_3, 0, 1023, 0, 255);
}
void val_f4() {
val_4 = analogRead(potpin4);
val_4 = map(val_4, 0, 1023, 0, 255);
}
void val_f5() {
val_5 = analogRead(potpin5);
val_5 = map(val_5, 0, 1023, 0, 255);
}
void val_f6() {
val_6 = analogRead(potpin6);
val_6 = map(val_6, 0, 1023, 0, 255);
}
// uint16_t numPixelsFlag = strip.numPixels()/3;
// uint16_t numPixelsFlagStart = strip.numPixels()/3;
// int leds = strip.numPixels();
// int stop = 0;
// void setup() {
// strip.begin();
// strip.setBrightness(250);
// strip.show(); // Initialize all pixels to 'off'
// }
// void loop() {
// // to_center();
// // int i = center(stop);
// // stop = i;
// rainbow_center();
// }
// void rainbow_center() {
// val_f2(); // яркость
// uint16_t i, j;
// for(j=0; j<leds*5; j++) { // 5 cycles of all colors on wheel
// // val_f2(); // яркость
// for(i=(leds/2); i>0; --i) {
// val_f0(); // яркость
// // val_f2(); // яркость
// strip.setPixelColor(i-1, Wheel(((i * leds*2 / strip.numPixels()) + j) & 255));
// // delay(val_2);
// strip.setBrightness(val_0);
// // strip.show();
// int l = leds-i;
// strip.setPixelColor(l, Wheel(((i * leds*2 / strip.numPixels()) + j) & 255));
// }
// strip.show();
// delay(val_2);
// }
// }
// uint32_t Wheel(byte WheelPos) {
// WheelPos = 255 - WheelPos;
// if(WheelPos < 85) {
// return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
// }
// if(WheelPos < 170) {
// WheelPos -= 85;
// return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
// }
// WheelPos -= 170;
// return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
// }
// // Функция бегущий цвет от центра
// int center(int s) {
// val_f0(); // яркость
// val_f2(); // скорость
// val_f3(); // R
// val_f4(); // G
// val_f5(); // B
// int start = 0;
// int end = 256;
// int r = rand() % (end - start + 1) + start;
// if (r == 0) {
// start = 100;
// }
// int g = rand() % (end - start + 1) + start;
// start = 0;
// int b = rand() % (end - start + 1) + start;
// int r2 = rand() % (end - start + 1) + start;
// if (r2 == 0) {
// start = 100;
// }
// int g2 = rand() % (end - start + 1) + start;
// start = 0;
// int b2 = rand() % (end - start + 1) + start;
// int start2 = 0;
// int end2 = 50;
// int stop = 0;
// int leds_rand = rand() % (end2 - start2 + 1) + start2;
// for(int i = (leds/2); i >= leds_rand; i--) {
// if (s < i) {
// leds_off(s);
// }
// leds_on(i, r2, g2, b2);
// int l = leds-i-1;
// s = s + 1;
// int s2 = leds - s;
// if (s2 > l) {
// leds_off(s2);
// }
// leds_on(l, r2, g2, b2);
// delay(val_2);
// strip.setBrightness(val_0);
// strip.show();
// stop = i;
// }
// return stop;
// }
// // Функция бегущий цвет от центра до края и обратно
// void center_end() {
// val_f0(); // яркость
// val_f2(); // скорость
// val_f3(); // R
// val_f4(); // G
// val_f5(); // B
// int start = 0;
// int end = 256;
// int r = rand() % (end - start + 1) + start;
// if (r == 0) {
// start = 100;
// }
// int g = rand() % (end - start + 1) + start;
// start = 0;
// int b = rand() % (end - start + 1) + start;
// strip.setBrightness(val_0);
// for(int i = (leds/2); i >= 0; i--) {
// leds_on(i, r, g, b);
// int l = leds - i;
// leds_on(l, r, g, b);
// delay(val_2);
// strip.show();
// }
// for(int i = (leds/2); i >= 0; i--) {
// leds_off(i);
// int l = leds - i;
// leds_off(l);
// delay(val_2);
// strip.show();
// }
// for(int i = 0; i <= (leds/2); i++) {
// leds_on(i, r, g, b);
// int l = leds - i;
// leds_on(l, r, g, b);
// delay(val_2);
// strip.show();
// }
// for(int i = 0; i <= (leds/2); i++) {
// leds_off(i);
// int l = leds - i;
// leds_off(l);
// delay(val_2);
// strip.show();
// }
// }
// void leds_on(int i, int r, int g, int b) {
// strip.setPixelColor(i, strip.Color(r, g, b));
// }
// void leds_off(int i) {
// strip.setPixelColor(i, strip.Color(0, 0, 0));
// }