#include <Arduino.h>
//TAIL FADE IN
int duration = 210; // 700 ms
float conv = (float) 255/100;// Converts PWM % values into 8 a bit register values
// setting PWM properties
const int freq = 500;
const int resolution = 8;
const int ledChannel1 = 0;
const int ledChannel2 = 1;
const int ledChannel3 = 2;
const int ledChannel4 = 3;
const int ledChannel5 = 4;
const int ledChannel6 = 5;
const int ledChannel7 = 6;
const int ledChannel8 = 7;
const int ledChannel9 = 8;
const int ledChannel10 = 9;
const int ledChannel11 = 10;
const int ledChannel12 = 11;
const int ledChannel13 = 12;
const int ledChannel14 = 13;
const int ledChannel15 = 14;
const int ledChannel16 = 15;
// PWM % in each segment at each step of 10 ms
int PWMControl[] = {0, 5, 10, 20, 40, 60, 80, 100};
const int LEDSelector[] = {ledChannel1, ledChannel2, ledChannel3, ledChannel4, ledChannel5, ledChannel6, ledChannel7, ledChannel8, ledChannel9, ledChannel10, ledChannel11, ledChannel12, ledChannel13, ledChannel14, ledChannel15, ledChannel16};
//PIN definitions
const int outPut1 = 13;
const int outPut2 = 27;
const int outPut3 = 26;
const int outPut4 = 25;
const int outPut5 = 12;
const int outPut6 = 14;
const int outPut7 = 32;
const int outPut8 = 33;
const int outPut9 = 15;
const int outPut10 = 2;
const int outPut11 = 0;
const int outPut12 = 4;
const int outPut13 = 16;
const int outPut14 = 17;
const int outPut15 = 5;
const int outPut16 = 18;
// Defina os pinos dos botões
const int buttonPin1 = 19;
int currentAnimation = 0;
int brightness = 0;
int fadeAmount = 50;
bool animationRunning = false;
void setup() {
Serial.begin(921600);
// configure LED PWM functionalitites
ledcSetup(ledChannel1, freq, resolution);
ledcSetup(ledChannel2, freq, resolution);
ledcSetup(ledChannel3, freq, resolution);
ledcSetup(ledChannel4, freq, resolution);
ledcSetup(ledChannel5, freq, resolution);
ledcSetup(ledChannel6, freq, resolution);
ledcSetup(ledChannel7, freq, resolution);
ledcSetup(ledChannel8, freq, resolution);
ledcSetup(ledChannel9, freq, resolution);
ledcSetup(ledChannel10, freq, resolution);
ledcSetup(ledChannel11, freq, resolution);
ledcSetup(ledChannel12, freq, resolution);
ledcSetup(ledChannel13, freq, resolution);
ledcSetup(ledChannel14, freq, resolution);
ledcSetup(ledChannel15, freq, resolution);
ledcSetup(ledChannel16, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(outPut1, ledChannel1);
ledcAttachPin(outPut2, ledChannel2);
ledcAttachPin(outPut3, ledChannel3);
ledcAttachPin(outPut4, ledChannel4);
ledcAttachPin(outPut5, ledChannel5);
ledcAttachPin(outPut6, ledChannel6);
ledcAttachPin(outPut7, ledChannel7);
ledcAttachPin(outPut8, ledChannel8);
ledcAttachPin(outPut9, ledChannel9);
ledcAttachPin(outPut10, ledChannel10);
ledcAttachPin(outPut11, ledChannel11);
ledcAttachPin(outPut12, ledChannel12);
ledcAttachPin(outPut13, ledChannel13);
ledcAttachPin(outPut14, ledChannel14);
ledcAttachPin(outPut15, ledChannel15);
ledcAttachPin(outPut16, ledChannel16);
Serial.println("FULL CONFIG DONE");
}
void loop() {
if (digitalRead(buttonPin1) == HIGH) {
if (!animationRunning) {
startAnimation();
} else {
stopAnimation();
}
delay(100);
}
}
void startAnimation() {
animationRunning = true;
while (animationRunning) {
executeAnimation();
// Add any additional logic or conditions for continuous animation
}
}
void stopAnimation() {
animationRunning = false;
}
void executeAnimation() {
switch (currentAnimation) {
case 0:
firstLoop();
break;
case 1:
secondLoop();
break;
case 2:
thirdLoop();
break;
case 3:
fourthLoop();
break;
}
//currentAnimation = (currentAnimation + 1) % 4;
delay(100); // Add a delay to make the transitions smoother, adjust as needed
}
//Primeiro void loop
void firstLoop() {
for (int i = 0; i < 16; i += 2) { // Ajuste para ativar de duas em duas
int currentChannel1 = LEDSelector[i];
int currentChannel2 = LEDSelector[i + 1];
// Ativação das LEDs
ledcWrite(currentChannel1, 255); // Define o brilho como 100%
ledcWrite(currentChannel2, 255);
delay(100); // Aguarde um curto período para observar o efeito
}
delay(500); // Aguarde um breve momento antes de reiniciar o ciclo
// Desativa todas as LEDs após o ciclo
for (int i = 0; i < 16; i++) {
int currentChannel = LEDSelector[i];
ledcWrite(currentChannel, 0); // Desativa a LED
}
}
//Segundo void loop
void secondLoop() {
for (int i = 0; i < 16; i += 2) { // Ativa de duas em duas
int currentChannel1 = LEDSelector[i];
int currentChannel2 = LEDSelector[i + 1];
// Ativação gradual das primeiras LEDs
for (int brightness = 0; brightness <= 127; brightness += 5) {
ledcWrite(currentChannel1, brightness);
ledcWrite(currentChannel2, brightness);
delay(10);
}
// Aguarda um curto período antes de ativar as próximas LEDs
delay(10);
// Ativação das próximas LEDs em 100%
if (i < 14) {
int nextChannel1 = LEDSelector[i + 2];
int nextChannel2 = LEDSelector[i + 3];
ledcWrite(nextChannel1, 255);
ledcWrite(nextChannel2, 255);
}
}
// Desliga todas as LEDs no final do ciclo
for (int i = 0; i < 16; i++) {
int currentChannel = LEDSelector[i];
ledcWrite(currentChannel, 0);
}
delay(10);
}
//Terceiro void loop
void thirdLoop() {
for (int i = 0; i < 16; i++) {
int currentChannel = LEDSelector[i];
ledcWrite(currentChannel, 255); // Define o brilho como 100%
delay(100); // Aguarde um curto período para observar o efeito
}
delay(500); // Aguarde um breve momento antes de reiniciar o ciclo
// Desativa todas as LEDs após o ciclo
for (int i = 0; i < 16; i++) {
int currentChannel = LEDSelector[i];
ledcWrite(currentChannel, 0); // Desativa a LED
}
}
//Quarto void loop
void fourthLoop() {
for (int i = 0; i < 16; i++) {
int currentChannel = LEDSelector[i];
// Ativação gradual da LED atual
for (int brightness = 0; brightness <= 127; brightness += 5) {
ledcWrite(currentChannel, brightness);
delay(10);
}
// Aguarda um curto período antes de ativar a próxima LED
delay(10);
// Ativação da próxima LED em 100%
if (i < 15) {
int nextChannel = LEDSelector[i + 1];
ledcWrite(nextChannel, 255);
}
}
// Desliga todas as LEDs
for (int i = 0; i < 16; i++) {
int currentChannel = LEDSelector[i];
ledcWrite(currentChannel, 0);
}
delay(10);
}