FastLED 12x12 Grid Blinking Happy Face

FastLED 12x12 Grid Blinking Happy Face

I managed to create the following Blinking Happy Face while experimenting with my WS2812B LED grid / matrix.



#include "FastLED.h"

#define NUM_LEDS 144
#define DATA_PIN 6
#define CLOCK_PIN 13 //You probably don't need to worry about this
#define BRIGHTNESS  48  //I believe this setting is over-ridden by the
                                             // third number in all the parentheses below
                                            // CHSV(#, #, BRIGHTNESS#)

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
            FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
     }

void loop() {

//Turn all 144 LEDs to yellow
fill_gradient(leds,0,CHSV(50,255,150),143,CHSV(50,255,150),SHORTEST_HUES); 

//Turn off some LEDs to make the circle
fill_gradient(leds,141,CHSV(50,255,0),143,CHSV(50,255,0),SHORTEST_HUES);
fill_gradient(leds,130,CHSV(50,255,0),134,CHSV(50,255,0),SHORTEST_HUES);
fill_gradient(leds,119,CHSV(50,255,0),121,CHSV(50,255,0),SHORTEST_HUES);
fill_gradient(leds,108,CHSV(50,255,0),108,CHSV(50,255,0),SHORTEST_HUES);
fill_gradient(leds,35,CHSV(50,255,0),35,CHSV(50,255,0),SHORTEST_HUES);
fill_gradient(leds,22,CHSV(50,255,0),24,CHSV(50,255,0),SHORTEST_HUES);
fill_gradient(leds,9,CHSV(50,255,0),13,CHSV(50,255,0),SHORTEST_HUES);
fill_gradient(leds,0,CHSV(50,255,0),2,CHSV(50,255,0),SHORTEST_HUES);

// Change some LEDs to blue to make the eyes
fill_gradient(leds,28,CHSV(160,255,80),31,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,39,CHSV(160,255,80),39,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,44,CHSV(160,255,80),44,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,99,CHSV(160,255,80),99,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,104,CHSV(160,255,80),104,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,86,CHSV(160,255,80),88,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,91,CHSV(160,255,80),93,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,75,CHSV(160,255,80),75,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,80,CHSV(160,255,80),80,CHSV(160,255,80),SHORTEST_HUES);
FastLED.show();
delay(3000);

//All the code below switches some blue LEDs to yellow and back to blue again for the blink
fill_gradient(leds,99,CHSV(50,255,150),99,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,104,CHSV(50,255,150),104,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,86,CHSV(160,255,80),88,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,91,CHSV(160,255,80),93,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,75,CHSV(160,255,80),75,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,80,CHSV(160,255,80),80,CHSV(160,255,80),SHORTEST_HUES);
FastLED.show();
delay(50);

fill_gradient(leds,99,CHSV(50,255,150),99,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,104,CHSV(50,255,150),104,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,86,CHSV(50,255,150),88,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,91,CHSV(50,255,150),93,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,75,CHSV(160,255,80),75,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,80,CHSV(160,255,80),80,CHSV(160,255,80),SHORTEST_HUES);
FastLED.show();
delay(50);

fill_gradient(leds,99,CHSV(50,255,150),99,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,104,CHSV(50,255,150),104,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,86,CHSV(50,255,150),88,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,91,CHSV(50,255,150),93,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,75,CHSV(50,255,150),75,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,80,CHSV(50,255,150),80,CHSV(50,255,150),SHORTEST_HUES);
FastLED.show();
delay(300);

fill_gradient(leds,99,CHSV(50,255,150),99,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,104,CHSV(50,255,150),104,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,86,CHSV(50,255,150),88,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,91,CHSV(50,255,150),93,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,75,CHSV(160,255,80),75,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,80,CHSV(160,255,80),80,CHSV(160,255,80),SHORTEST_HUES);
FastLED.show();
delay(50);

fill_gradient(leds,99,CHSV(50,255,150),99,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,104,CHSV(50,255,150),104,CHSV(50,255,150),SHORTEST_HUES);
fill_gradient(leds,86,CHSV(160,255,80),88,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,91,CHSV(160,255,80),93,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,75,CHSV(160,255,80),75,CHSV(160,255,80),SHORTEST_HUES);
fill_gradient(leds,80,CHSV(160,255,80),80,CHSV(160,255,80),SHORTEST_HUES);
FastLED.show();
delay(50);

}

1 comment:

  1. #define BRIGHTNESS 48 You wrote that the value of BRIGHTNESS was overridden by CHSV(#, #, BRIGHTNESS). This is incorrect.

    #define BRIGHTNESS 48 -- replaces every instance of BRIGHTNESS with the value 48. BRIGHTNESS becomes a constant value.

    CHSV(#, #, BRIGHTNESS) -- replaces BRIGHTNESS with the value 48, as in CHSV(#, #, 48). If you want the lights to be brighter, increase the value of BRIGHTNESS.

    ReplyDelete