fix second runner LED birghtness for non 60 LED strips

This commit is contained in:
King Kévin 2016-04-05 09:54:32 +02:00
parent 57998de65a
commit 577d1ba607
1 changed files with 13 additions and 12 deletions

25
main.c
View File

@ -169,9 +169,9 @@ static void clock_clear(void)
*/
static void clock_show_time(uint32_t time)
{
uint32_t led_hour = (WS2812B_LEDS*(255*(uint64_t)(time%ticks_midday)))/ticks_midday; // scale to LED brightnesses for hours
uint32_t led_minute = (WS2812B_LEDS*(255*(uint64_t)(time%ticks_hour)))/ticks_hour; // scale to LED brightnesses for minutes
if (led_hour>=WS2812B_LEDS*255 || led_minute>=WS2812B_LEDS*255) { // a calculation error occurred
uint32_t led_hour = (WS2812B_LEDS*(256*(uint64_t)(time%ticks_midday)))/ticks_midday; // scale to LED brightnesses for hours
uint32_t led_minute = (WS2812B_LEDS*(256*(uint64_t)(time%ticks_hour)))/ticks_hour; // scale to LED brightnesses for minutes
if (led_hour>=WS2812B_LEDS*256 || led_minute>=WS2812B_LEDS*256) { // a calculation error occurred
return;
}
// show hours and minutes on LEDs
@ -226,17 +226,18 @@ static void clock_show_time(uint32_t time)
if (time%ticks_minute==0) {
return;
}
uint16_t led_second = (WS2812B_LEDS*(time%ticks_minute))/ticks_minute; // get LED for seconds
uint8_t brightness_second = (255*(time%ticks_second))/ticks_second; // get brightness for seconds
uint32_t led_second = (WS2812B_LEDS*(256*(uint64_t)(time%ticks_minute)))/ticks_minute; // scale to LED brightnesses for seconds
uint8_t brightness_second = led_second%256; // get brightness for seconds for last LED
uint16_t second_led = (WS2812B_LEDS*(time%ticks_minute))/ticks_minute; // get LED for seconds (we only use the last LED as runner instead of all LEDs as arc)
// set seconds LED
clock_leds[led_second*3+0] = brightness_second;
//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)
clock_leds[second_led*3+0] = brightness_second;
//clock_leds[second_led*3+1] = 0; // clear other colors (minutes/hours indication)
//clock_leds[second_led*3+2] = 0; // clear other colors (minutes/hours indication)
// set previous seconds 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; // clear other colors (minutes/hours indication)
//clock_leds[led_second*3+2] = 0; // clear other colors (minutes/hours indication)
second_led = ((second_led==0) ? WS2812B_LEDS-1 : second_led-1); // previous LED
clock_leds[second_led*3+0] = 0xff-brightness_second;
//clock_leds[second_led*3+1] = 0; // clear other colors (minutes/hours indication)
//clock_leds[second_led*3+2] = 0; // clear other colors (minutes/hours indication)
}
/** @brief set the LEDs