fix time display
This commit is contained in:
parent
98ea89112a
commit
29acf424f7
8
main.c
8
main.c
|
@ -120,13 +120,13 @@ static void clock_hours(void)
|
||||||
* green is for minutes, blur for hours */
|
* green is for minutes, blur for hours */
|
||||||
static void clock_hour(uint32_t time)
|
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_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
|
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
|
if (led_hour>=WS2812B_LEDS*255 || led_minute>=WS2812B_LEDS*255) { // a calculation error occurred
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// set LEDs
|
// show hours and minutes on LEDs
|
||||||
if (led_hour>led_minute) {
|
if (led_hour>led_minute) {
|
||||||
// show hours in blue (and clear other LEDs)
|
// show hours in blue (and clear other LEDs)
|
||||||
for (uint16_t led=0; led<WS2812B_LEDS; led++) {
|
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];
|
led_hour -= clock_leds[led*3+2];
|
||||||
}
|
}
|
||||||
// show minutes in green (override hours)
|
// 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;
|
clock_leds[led*3+0] = 0;
|
||||||
if (led_minute>=0xff) { // full minutes
|
if (led_minute>=0xff) { // full minutes
|
||||||
clock_leds[led*3+1] = 0xff;
|
clock_leds[led*3+1] = 0xff;
|
||||||
|
@ -163,7 +163,7 @@ static void clock_hour(uint32_t time)
|
||||||
clock_leds[led*3+2] = 0;
|
clock_leds[led*3+2] = 0;
|
||||||
}
|
}
|
||||||
// show hours in blue (override minutes)
|
// 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+0] = 0;
|
||||||
clock_leds[led*3+1] = 0;
|
clock_leds[led*3+1] = 0;
|
||||||
if (led_hour>=0xff) { // full hours
|
if (led_hour>=0xff) { // full hours
|
||||||
|
|
Loading…
Reference in New Issue