show time hours and minutes
This commit is contained in:
parent
02658f2c45
commit
5379d653c9
62
main.c
62
main.c
@ -114,25 +114,61 @@ static void clock_hours(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* set hour progress on clock LEDs */
|
||||
/* set hour progress on clock LEDs
|
||||
* the hour/time time indication are full arcs, not only position
|
||||
* whatever arc is smaller is displayed first
|
||||
* 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; // scale to LED brightnesses
|
||||
printf("led hour: %lu, brightness: %lu\n", led_hour/255, led_hour%255);
|
||||
if (led_hour>=WS2812B_LEDS*255) { // a calculation error occurred
|
||||
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
|
||||
return;
|
||||
}
|
||||
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;
|
||||
// set LEDs
|
||||
for (uint16_t led=0; led<WS2812B_LEDS; led++) {
|
||||
// determine order of hour/minute display
|
||||
if (led_hour>led_minute) {
|
||||
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];
|
||||
}
|
||||
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];
|
||||
}
|
||||
led_hour -= clock_leds[led*3+2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* set the LEDs */
|
||||
|
Loading…
Reference in New Issue
Block a user