#include <Adafruit_NeoPixel.h>
#define strip1_Pin 5 // Pino de sinal
const int strip1_NumLeds = 32; // Número de Leds
const int MAX_NUM_LEDS = 32;
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(strip1_NumLeds, strip1_Pin, NEO_GRB + NEO_KHZ800);
float valBrightnessAll = 255;
// Variáveis de Cores
uint32_t black,blue,chocolate,cyan,green,gold,orange,pink,purple,red,white,yellow;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
strip1.begin();
strip1.show();
// Inicia Brilho
strip1.setBrightness(valBrightnessAll);
// Atribui valores aos nomes das Cores Padrão
CoresPadrao();
}
void loop() {
// put your main code here, to run repeatedly:
delay(100); // this speeds up the simulation
for (int conta=0; conta<MAX_NUM_LEDS; conta++) {
strip1.setPixelColor(conta, corAleatoria());
strip1.show();
delay(500);
}
ApagaLEDS();
}
// Variáveis de Cores Basicas atribui valores
void CoresPadrao() {
black = strip1.Color(0, 0, 0);
red = strip1.Color(255, 0, 0);
green = strip1.Color(0, 255, 0);
blue = strip1.Color(0, 0, 255);
cyan = strip1.Color(0, 255, 255);
purple = strip1.Color(255, 0, 255);
yellow = strip1.Color(255, 255, 0);
white = strip1.Color(255, 255, 255);
chocolate = strip1.Color(210,105,30);
gold = strip1.Color(153, 153, 0);
orange = strip1.Color(255, 153, 0);
pink = strip1.Color(255,192,203);
}
// Apaga Todos os Leds da Fita
void ApagaLEDS() {
int i = 0;
for (i = 0; i < strip1.numPixels(); i++) {
strip1.setPixelColor(i, 0,0,0);
}
strip1.show();
delay (10);
}
// Cores Aleatórias (12 Opções)
uint32_t corAleatoria() {
int num = random(1,11);
//Serial.println(num);
switch (num) {
case 1: return white; break;
case 2: return blue; break;
case 3: return red; break;
case 4: return green; break;
case 5: return orange; break;
case 6: return purple; break;
case 7: return pink; break;
case 8: return yellow; break;
case 9: return chocolate; break;
case 10: return cyan; break;
case 11: return gold; break;
default: return black; break;
}
}