modify how to show time (more code, but more readable)

This commit is contained in:
King Kévin 2016-02-23 22:03:52 +01:00
parent 5379d653c9
commit 98ea89112a
1 changed files with 39 additions and 34 deletions

73
main.c
View File

@ -127,40 +127,11 @@ static void clock_hour(uint32_t time)
return;
}
// set LEDs
for (uint16_t led=0; led<WS2812B_LEDS; led++) {
// determine order of hour/minute display
if (led_hour>led_minute) {
if (led_hour>led_minute) {
// show hours in blue (and clear other LEDs)
for (uint16_t led=0; led<WS2812B_LEDS; led++) {
clock_leds[led*3+0] = 0;
if (led_minute>=0xff) { // full minutes
clock_leds[led*3+1] = 0xff;
} else { // running minutes
clock_leds[led*3+1] = led_minute;
}
led_minute -= clock_leds[led*3+1];
if (led_minute!=0) {
clock_leds[led*3+2] = 0;
led_hour -= 0xff;
} else {
if (led_hour>=0xff) { // full hours
clock_leds[led*3+2] = 0xff;
} else { // running hours
clock_leds[led*3+2] = led_hour;
}
led_hour -= clock_leds[led*3+2];
}
} else {
clock_leds[led*3+0] = 0;
if (led_hour!=0) {
clock_leds[led*3+1] = 0;
led_minute -= 0xff;
} else {
if (led_minute>=0xff) { // full minutes
clock_leds[led*3+1] = 0xff;
} else { // running minutes
clock_leds[led*3+1] = led_minute;
}
led_minute -= clock_leds[led*3+1];
}
clock_leds[led*3+1] = 0;
if (led_hour>=0xff) { // full hours
clock_leds[led*3+2] = 0xff;
} else { // running hours
@ -168,7 +139,41 @@ 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++) {
clock_leds[led*3+0] = 0;
if (led_minute>=0xff) { // full minutes
clock_leds[led*3+1] = 0xff;
} else { // running minutes
clock_leds[led*3+1] = led_minute;
}
led_minute -= clock_leds[led*3+1];
clock_leds[led*3+2] = 0;
}
} else {
// show minutes in green (and clear other LEDs)
for (uint16_t led=0; led<WS2812B_LEDS; led++) {
clock_leds[led*3+0] = 0;
if (led_minute>=0xff) { // full minutes
clock_leds[led*3+1] = 0xff;
} else { // running minutes
clock_leds[led*3+1] = led_minute;
}
led_minute -= clock_leds[led*3+1];
clock_leds[led*3+2] = 0;
}
// show hours in blue (override minutes)
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
clock_leds[led*3+2] = 0xff;
} else { // running hours
clock_leds[led*3+2] = led_hour;
}
led_hour -= clock_leds[led*3+2];
}
}
}
/* set the LEDs */