fix time display

This commit is contained in:
King Kévin 2016-02-23 23:38:08 +01:00
parent 98ea89112a
commit 29acf424f7
1 changed files with 4 additions and 4 deletions

8
main.c
View File

@ -120,13 +120,13 @@ static void clock_hours(void)
* green is for minutes, blur for hours */
static void clock_hour(uint32_t time)
{
time %= ticks_midday; // the LED strip can only display 12 hours
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
printf("hours: %lu, minutes: %lu\n",led_hour,led_minute);
if (led_hour>=WS2812B_LEDS*255 || led_minute>=WS2812B_LEDS*255) { // a calculation error occurred
return;
}
// set LEDs
// show hours and minutes on LEDs
if (led_hour>led_minute) {
// show hours in blue (and clear other LEDs)
for (uint16_t led=0; led<WS2812B_LEDS; led++) {
@ -140,7 +140,7 @@ static void clock_hour(uint32_t time)
led_hour -= clock_leds[led*3+2];
}
// show minutes in green (override hours)
for (uint16_t led=0; led<WS2812B_LEDS || led_minute>0; led++) {
for (uint16_t led=0; led<WS2812B_LEDS && led_minute>0; led++) {
clock_leds[led*3+0] = 0;
if (led_minute>=0xff) { // full minutes
clock_leds[led*3+1] = 0xff;
@ -163,7 +163,7 @@ static void clock_hour(uint32_t time)
clock_leds[led*3+2] = 0;
}
// show hours in blue (override minutes)
for (uint16_t led=0; led<WS2812B_LEDS || led_hour>0; led++) {
for (uint16_t led=0; led<WS2812B_LEDS && led_hour>0; led++) {
clock_leds[led*3+0] = 0;
clock_leds[led*3+1] = 0;
if (led_hour>=0xff) { // full hours