// Paso #1: Configuración
#include <FastLED.h>
#define NUM_LEDS 16
#define DATA_PIN 9 // Arduino Uno
#define BRIGHTNESS 200
#define COLOR_ORDER GRB // Green - Red - Blue
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
blackOut();
delay(1000);
}
void loop() {
fillOut(500);
dFill(20,4);
fadeMoving(10,10);
colorRain();
lightUp(10,10);
Strobe(0xff, 0xff, 0xff, 5, 20, 50);
Estrellas(0xff, 0xff, 0xff, 0);
Estrellas(random(255), random(255), random(255), 0);
colorWipe(0x00,0xff,0x00, 20);
colorWipe(0x00,0x00,0x00, 20);
Arcoiris(5);
Teatro(0xff,0xff,0xff,50);
Meteoro(0xff,0xff,0xff,10, 64, true, 30);
Circo(0xff,0xff,0x00, 50);
Choque();
tresColores();
}
void pines(){
pinMode(13, INPUT);
}
/*Encender toda la Matriz sin retraso*/
void fillOut(int t){
//Red
for(int x = 0; x <= NUM_LEDS; x++)
{
leds[x] = 0xFF4040; //RoseRed
}
FastLED.show();
delay(t);
//Green
for(int x = 0; x <= NUM_LEDS; x++)
{
leds[x] = 0x00FF7F; //SpringGreen
}
FastLED.show();
delay(t);
//Blue
for(int x = 0; x <= NUM_LEDS; x++)
{
leds[x] = 0x4876FF; //RoyalBlue
}
FastLED.show();
delay(t);
}
/*Enciende la Matriz con un retraso 't' y un fade 'f'
Valores sugeridos t = 20; f = 4*/
void dFill(int timing, int fade){
for(int d = 0; d <= NUM_LEDS; d++)
{
leds[d] = 0x458B74; //aquamarine4
FastLED.show();
delay(timing);
fadeToBlackBy(leds,NUM_LEDS,fade);
}
}
/*Desplaza un LED con degradado en la Matriz, valores sugeridos v = 10, f = 10*/
void fadeMoving(int v, int f){
for(int m = 0; m <= NUM_LEDS; m++)
{
leds[m] = 0xFF4040; //RoseRed
FastLED.show();
fadeToBlackBy(leds,NUM_LEDS,f);
//leds[m] = CRGB::Black; // Desplazamiento tradicional
delay(v);
}
for(int m = 99; m >= 0; m--){
leds[m] = 0x6959CD; //SlateBlue3
FastLED.show();
fadeToBlackBy(leds,NUM_LEDS,f/2); //fade/2
//leds[m] = CRGB::Black; // Desplazamiento tradicional
delay(v);
}
}
/*Genera destellos de colores en posiciones aleatorias con devanecimiento*/
void colorRain(){
fadeToBlackBy(leds,NUM_LEDS,5);
int pos = random16(NUM_LEDS); // Guarda una posición aleatoria
leds[pos] += CRGB(random(255),100,random(255)); // Escribe el LED guardado con un color aleatorio
FastLED.show();
}
/*Desplaza un LED con degradado claro en la Matriz, valores sugeridos v = 10, f = 10*/
void lightUp(int timing, int light){
int8_t hue = 0;
for(int l = 0; l <= NUM_LEDS; l++){
leds[l] = CRGB(100,hue,200);//0x8B8B00+hue; AQUI SE ESTABLECE EL COMOLOR
FastLED.show();
fadeLightBy (leds, NUM_LEDS, light); //leds, NUM_LEDS, factor_Amount
//fadeToBlackBy (leds, NUM_LEDS, light);
delay(timing);
hue+=3;
}
}
/*APAGA TODA LA TIRA*/
void blackOut(){
for(int f = 0; f <= NUM_LEDS; f++)
{
leds[f] = 0x000000;
}
FastLED.show();
}
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
for(int j = 0; j < StrobeCount; j++) {
setAll(red,green,blue);
showStrip();
delay(FlashDelay);
setAll(0,0,0);
showStrip();
delay(FlashDelay);
}
delay(EndPause);
}
void Estrellas(byte red, byte green, byte blue, int SpeedDelay) {
int Pixel = random(NUM_LEDS);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
setPixel(Pixel,0,0,0);
}
void Circo(byte red, byte green, byte blue, int WaveDelay) {
int Position=0;
for(int j=0; j<NUM_LEDS*2; j++)
{
Position++; // = 0; //Position + Rate;
for(int i=0; i<NUM_LEDS; i++) {
// sine wave, 3 offset waves make a rainbow!
//float level = sin(i+Position) * 127 + 128;
//setPixel(i,level,0,0);
//float level = sin(i+Position) * 127 + 128;
setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
((sin(i+Position) * 127 + 128)/255)*green,
((sin(i+Position) * 127 + 128)/255)*blue);
}
showStrip();
delay(WaveDelay);
}
}
void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
for(uint16_t i=0; i<NUM_LEDS; i++) {
setPixel(i, red, green, blue);
showStrip();
delay(SpeedDelay);
}
}
void Arcoiris(int SpeedDelay) {
byte *c;
uint16_t i, j;
for(j=0; j<256*2; j++) { // 5 cycles of all colors on wheel
for(i=0; i< NUM_LEDS; i++) {
c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}
showStrip();
delay(SpeedDelay);
}
}
byte * Wheel(byte WheelPos) {//esta funcion la ocupa el arcoiris
static byte c[3];
if(WheelPos < 85) {
c[0]=WheelPos * 3;
c[1]=255 - WheelPos * 3;
c[2]=0;
} else if(WheelPos < 170) {
WheelPos -= 85;
c[0]=255 - WheelPos * 3;
c[1]=0;
c[2]=WheelPos * 3;
} else {
WheelPos -= 170;
c[0]=0;
c[1]=WheelPos * 3;
c[2]=255 - WheelPos * 3;
}
return c;
}
void Teatro(byte red, byte green, byte blue, int SpeedDelay) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < NUM_LEDS; i=i+3) {
setPixel(i+q, red, green, blue); //turn every third pixel on
}
showStrip();
delay(SpeedDelay);
for (int i=0; i < NUM_LEDS; i=i+3) {
setPixel(i+q, 0,0,0); //turn every third pixel off
}
}
}
}
void Meteoro(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0,0,0);
for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}
showStrip();
delay(SpeedDelay);
}
}
void fadeToBlack(int ledNo, byte fadeValue) { //ESTA FUNCION LA OCUPÁ METEORO
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
strip.setPixelColor(ledNo, r,g,b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}
void Choque() {
uint16_t posBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 32767);
uint16_t posBeat4 = beatsin16(60, 0, NUM_LEDS - 1, 0, 32767);
// Wave for LED color
uint8_t colBeat = beatsin8(45, 0, 255, 0, 0);
leds[(posBeat + posBeat2) / 2] = CHSV(colBeat, 255, 255);
leds[(posBeat3 + posBeat4) / 2] = CHSV(colBeat, 255, 255);
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
}
void tresColores() {
uint16_t sinBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(30, 0, NUM_LEDS - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 43690);
uint16_t sinBeat4 = beatsin16(30, 0, NUM_LEDS - 1, 0, 32340);
leds[sinBeat] = CRGB::Blue;
leds[sinBeat2] = CRGB::Red;
leds[sinBeat3] = CRGB::White;
leds[sinBeat4] = CRGB(238, 255, 0);
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
}
////////////////////////////////////////
////////////FUNCIONES OBLIGATORIAS/////////////////
///////////////////////////////////////
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}