also show seconds
This commit is contained in:
parent
29acf424f7
commit
9747b98dfb
20
main.c
20
main.c
|
@ -122,7 +122,6 @@ static void clock_hour(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_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;
|
||||||
}
|
}
|
||||||
|
@ -174,6 +173,16 @@ static void clock_hour(uint32_t time)
|
||||||
led_hour -= clock_leds[led*3+2];
|
led_hour -= clock_leds[led*3+2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
// set second LED
|
||||||
|
clock_leds[led_second*3+0] = brightness_second;
|
||||||
|
clock_leds[led_second*3+1] = 0;
|
||||||
|
clock_leds[led_second*3+2] = 0;
|
||||||
|
// set previous LED
|
||||||
|
clock_leds[((led_second-1)%WS2812B_LEDS)*3+0] = 0xff-brightness_second;
|
||||||
|
clock_leds[((led_second-1)%WS2812B_LEDS)*3+1] = 0;
|
||||||
|
clock_leds[((led_second-1)%WS2812B_LEDS)*3+2] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set the LEDs */
|
/* set the LEDs */
|
||||||
|
@ -221,6 +230,13 @@ int main(void)
|
||||||
uint32_t time = 0; // the time to display
|
uint32_t time = 0; // the time to display
|
||||||
bool clear = true; // clear or display time
|
bool clear = true; // clear or display time
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
clock_hour(time); // set an increment time
|
||||||
|
leds_set(); // set the colors of all LEDs
|
||||||
|
ws2812b_transmit(); // transmit set color
|
||||||
|
time += 10;
|
||||||
|
}
|
||||||
|
|
||||||
bool action = false; // if an action has been performed don't go to sleep
|
bool action = false; // if an action has been performed don't go to sleep
|
||||||
button_flag = false; // reset button flag
|
button_flag = false; // reset button flag
|
||||||
char c; // to store received character
|
char c; // to store received character
|
||||||
|
@ -249,7 +265,7 @@ int main(void)
|
||||||
} else {
|
} else {
|
||||||
printf("%02lu:%02lu\n", time/ticks_hour, (time%ticks_hour)/ticks_minute);
|
printf("%02lu:%02lu\n", time/ticks_hour, (time%ticks_hour)/ticks_minute);
|
||||||
clock_hour(time); // set time
|
clock_hour(time); // set time
|
||||||
time += ticks_minute; // increment time
|
time += 1; // increment time
|
||||||
}
|
}
|
||||||
leds_set(); // set the colors of all LEDs
|
leds_set(); // set the colors of all LEDs
|
||||||
ws2812b_transmit(); // transmit set color
|
ws2812b_transmit(); // transmit set color
|
||||||
|
|
Loading…
Reference in New Issue