Sunrise with LED panel

Hello and welcome to our post today.

 

One community member took inspiration from our posts, and one Radio clock  built with alarm clock. Before the morning alarm, a U-64 RGB panel should simulate the light of a sunrise to enable a more gentle wake up.

The FastLED library that I prefer offers the possibility to define my own color gradients.

Each LED consists of a very small red, green and blue LED as well as a very small control chip that controls the brightness of the individual colors.

Each color can be set with a value between 0 (off) and 255 (full brightness).

The color and brightness of the LED are made up of 3 values, each for red, green and blue.

red

green

blue

LED color

255

0

0

red

0

255

0

green

0

0

255

blue

255

255

0

yellow

0

255

255

Cyan

 

Now that we know how the colors are put together, all we have to do is specify a gradient.

Thanks to a relatively new function in the FastLED library, we can easily define such processes.

The whole thing can be thought of as a list. The first line is the line number, followed by the values ​​for red, green and blue. We can adjust this for each line.

So if my table was 255 rows long, it would take a lot of work to manually enter the appropriate values ​​for each row.

Using DEFINE_GRADIENT_PALETTE we can specify the desired value for certain rows in our table. In the example below, I do this for lines 0, 128, 224 and 255.
The result is a table with 255 rows in which the different color gradients are calculated for me.

If I now use ColorFromPalette () to query the color values ​​for line 64, I get the average between 0 and 128.

In practice, the function is called as follows:

DEFINE_GRADIENT_PALETTE ( * name_my_palette * ) {
* Line number *, * Value for red *, * Value for green *, * Value for blue *
};
In the example it looks like this:
DEFINE_GRADIENT_PALETTE( sunrise_gp ) {   0,     0,  0,  0,   //black
128,   240,  0,  0,   //red
224,   240,240,  0,   //yellow
255,   128,128,240 }; // very light blue

So that we can use the table, however, we still have to write the "sunrise_gp" table to a variable using CRGBPalette16 () or CRGBPalette256 ().

CRGBPalette256 sunrisePal = sunrise_gp;

Then we can determine the color at a specific position (= heatIndex) using the following command.

CRGB color = ColorFromPalette(sunrisePal, heatIndex);

Then we use fill_solid () to set the color of all LEDs to the determined color:

fill_solid(leds, NUM_LEDS, color);



Here is the complete sketch:

#include <FastLED.H>

#define DATA_PIN    3
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    64
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          128

DEFINE_GRADIENT_PALETTE( sunrise_gp ) {   0,     0,  0,  0,   //black
128,   240,  0,  0,   //red
224,   240,240,  0,   //yellow
255,   128,128,240 }; // very light blue

void set up() {   delay(1000);   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);   FastLED.setBrightness(BRIGHTNESS);   fill_solid(leds, NUM_LEDS, CRGB(0,0,0)); // All pixels off   FastLED.show();    sunrise(); // Play sunrise
}    void loop()
{
}

void sunrise() {   static uint16_t heatIndex = 0; // start out at 0   for (heatIndex=0; heatIndex<255; heatIndex++) {   CRGBPalette256 sunrisePal = sunrise_gp;   CRGB color = ColorFromPalette(sunrisePal, heatIndex);   // fill the entire strip with the current color   fill_solid(leds, NUM_LEDS, color);   FastLED.show();    FastLED.delay(250);   }
}

 

With the FastLED.delay we can adjust the speed.

To implement the whole thing in an alarm clock, just the function sunrise ()be called before the alarm itself, and the alarm clock starts the gentle wake-up process.

If you already have experience with our MP3 module or the TonUINO set, you can also be suitably sprinkled with the sound of the sea or twittering of birds.

I hope today's post will help you get a grip on your Neopixel gradients. Not every Christmas tree illuminated with neopixels has to shine in rainbow colors.

 

 

Projects for beginners

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN