add full hour animation
This commit is contained in:
parent
3914df5590
commit
456ca4def2
47
main.c
47
main.c
@ -149,19 +149,6 @@ static void clock_clear(void)
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief set hours mark on clock LEDs
|
||||
* @note LEDs need to be set separately
|
||||
*/
|
||||
static void clock_hours(void)
|
||||
{
|
||||
for (uint8_t hour=0; hour<12; hour++) {
|
||||
uint16_t led = WS2812B_LEDS/12*hour;
|
||||
clock_leds[led*3+0] = 0xff;
|
||||
clock_leds[led*3+1] = 0xff;
|
||||
clock_leds[led*3+2] = 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief show time on LED clock
|
||||
* @param[in] time in ticks to show
|
||||
* @details show hours and minutes progress as full arcs, show second position as marker. the brightness of the LED shows the progress of the unit. hours are blue, minutes green, seconds red
|
||||
@ -291,6 +278,27 @@ static void clock_animate_time(uint32_t time)
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief show animation with fading hours mark on clock LEDs
|
||||
*/
|
||||
static void clock_hours(void)
|
||||
{
|
||||
for (uint16_t i=0; i<512; i++) { // fade in and out
|
||||
uint8_t brightness = (i>255 ? 512-i-1 : i); // get fade brightness
|
||||
for (uint8_t hour=0; hour<12; hour++) { // set all hour colors
|
||||
uint16_t led = WS2812B_LEDS/12*hour; // get LED four hour mark
|
||||
clock_leds[led*3+0] = brightness; // set brightness
|
||||
clock_leds[led*3+1] = brightness; // set brightness
|
||||
clock_leds[led*3+2] = brightness; // set brightness
|
||||
}
|
||||
clock_leds_set(); // set the colors of all LEDs
|
||||
ws2812b_transmit(); // transmit set color
|
||||
// delay some time for the animation
|
||||
for (uint32_t j=0; j<40000; j++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief process user command
|
||||
* @param[in] str user command string (\0 ended)
|
||||
*/
|
||||
@ -388,7 +396,6 @@ int main(void)
|
||||
|
||||
// setup WS2812b LEDs
|
||||
ws2812b_setup(); // setup WS2812b LEDs
|
||||
clock_hours(); // show hour markers
|
||||
clock_clear(); // clear all LEDs
|
||||
clock_leds_set(); // set the colors of all LEDs
|
||||
ws2812b_transmit(); // transmit set color
|
||||
@ -473,13 +480,19 @@ int main(void)
|
||||
while (time_flag) { // time passed
|
||||
time_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
if ((current_time%ticks_minute)==0) { // sync each minute
|
||||
if ((current_time%ticks_second)==0) { // one second passed
|
||||
//printf("%02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
||||
}
|
||||
if ((current_time%ticks_minute)==0) { // one minute passed
|
||||
rtc_time = rtc_read_time(); // get RTC time/date
|
||||
current_time = rtc_time[2]*ticks_hour+rtc_time[1]*ticks_minute+rtc_time[0]*ticks_second; // calculate current time
|
||||
current_time = rtc_time[2]*ticks_hour+rtc_time[1]*ticks_minute+rtc_time[0]*ticks_second; // sync current time
|
||||
printf("it is now %02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
||||
}
|
||||
if ((current_time%ticks_hour)==0) { // one hours passed
|
||||
clock_hours(); // show hour markers
|
||||
}
|
||||
clock_set_time(current_time); // set time
|
||||
if ((current_time%ticks_second)==0) { // print each second
|
||||
if ((current_time%ticks_second)==0) { // on second passed
|
||||
//printf("%02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user