improve: set only LED if changed
This commit is contained in:
parent
c8e5c4f7fd
commit
6edccc845d
22
main.c
22
main.c
|
@ -206,23 +206,29 @@ static void clock_show_time(uint32_t time)
|
|||
uint8_t brightness_second = (255*(time%ticks_second))/ticks_second; // get brightness for seconds
|
||||
// set second LED
|
||||
clock_leds[led_second*3+0] = brightness_second;
|
||||
//clock_leds[led_second*3+1] = 0;
|
||||
//clock_leds[led_second*3+2] = 0;
|
||||
//clock_leds[led_second*3+1] = 0; // clear other colors (minutes/hours indication)
|
||||
//clock_leds[led_second*3+2] = 0; // clear other colors (minutes/hours indication)
|
||||
// set previous LED
|
||||
led_second = (led_second==0) ? WS2812B_LEDS-1 : led_second-1; // previous LED
|
||||
clock_leds[led_second*3+0] = 0xff-brightness_second;
|
||||
//clock_leds[led_second*3+1] = 0;
|
||||
//clock_leds[led_second*3+2] = 0;
|
||||
//clock_leds[led_second*3+1] = 0; // clear other colors (minutes/hours indication)
|
||||
//clock_leds[led_second*3+2] = 0; // clear other colors (minutes/hours indication)
|
||||
}
|
||||
|
||||
/** @brief set the LEDs
|
||||
* @details set the LED colors on WS2812b LEDs
|
||||
* @note WS2812b LED color values need to be transmitted separately
|
||||
*/
|
||||
static void leds_set(void)
|
||||
static void clock_leds_set(void)
|
||||
{
|
||||
static uint8_t clock_leds_old[WS2812B_LEDS*3] = {0}; // backup so to only set when value changed
|
||||
for (uint16_t i=0; i<LENGTH(clock_leds)/3; i++) {
|
||||
ws2812b_set_rgb(i,clock_leds[i*3+0],clock_leds[i*3+1],clock_leds[i*3+2]);
|
||||
if (clock_leds[i*3+0]!=clock_leds_old[i*3+0] || clock_leds[i*3+1]!=clock_leds_old[i*3+1] || clock_leds[i*3+2]!=clock_leds_old[i*3+2]) { // only set when value changed (since this costs time)
|
||||
clock_leds_old[i*3+0] = clock_leds[i*3+0]; // memorise change
|
||||
clock_leds_old[i*3+1] = clock_leds[i*3+1]; // memorise change
|
||||
clock_leds_old[i*3+2] = clock_leds[i*3+2]; // memorise change
|
||||
ws2812b_set_rgb(i,clock_leds[i*3+0],clock_leds[i*3+1],clock_leds[i*3+2]); // set new value (this costs time)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +238,7 @@ static void leds_set(void)
|
|||
static void clock_set_time(uint32_t time)
|
||||
{
|
||||
clock_show_time(time); // set time
|
||||
leds_set(); // set the colors of all LEDs
|
||||
clock_leds_set(); // set the colors of all LEDs
|
||||
ws2812b_transmit(); // transmit set color
|
||||
}
|
||||
|
||||
|
@ -294,7 +300,7 @@ int main(void)
|
|||
ws2812b_setup(); // setup WS2812b LEDs
|
||||
clock_hours(); // show hour markers
|
||||
clock_clear(); // clear all LEDs
|
||||
leds_set(); // set the colors of all LEDs
|
||||
clock_leds_set(); // set the colors of all LEDs
|
||||
ws2812b_transmit(); // transmit set color
|
||||
|
||||
// setup RTC module
|
||||
|
|
Loading…
Reference in New Issue