animation to set initial time
This commit is contained in:
parent
9747b98dfb
commit
7347a3dd8f
50
main.c
50
main.c
@ -114,11 +114,12 @@ static void clock_hours(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
/* show time on LED clock
|
||||
* 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 */
|
||||
static void clock_show_time(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_minute = (WS2812B_LEDS*(255*(uint64_t)(time%ticks_hour)))/ticks_hour; // scale to LED brightnesses for minutes
|
||||
@ -173,6 +174,10 @@ static void clock_hour(uint32_t time)
|
||||
led_hour -= clock_leds[led*3+2];
|
||||
}
|
||||
}
|
||||
// don't show seconds on full minute (better for first time setting, barely visible else)
|
||||
if (time%ticks_minute==0) {
|
||||
return;
|
||||
}
|
||||
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
|
||||
@ -221,6 +226,7 @@ int main(void)
|
||||
|
||||
ws2812b_setup(); // setup WS2812b LEDs
|
||||
clock_hours(); // show hour markers
|
||||
clock_clear(); // clear all LEDs
|
||||
leds_set(); // set the colors of all LEDs
|
||||
ws2812b_transmit(); // transmit set color
|
||||
|
||||
@ -228,15 +234,28 @@ int main(void)
|
||||
led_on(); // switch on LED to indicate setup completed
|
||||
|
||||
uint32_t time = 0; // the time to display
|
||||
bool clear = true; // clear or display time
|
||||
|
||||
while (true) {
|
||||
clock_hour(time); // set an increment time
|
||||
uint32_t current_time = 6*ticks_hour+45*ticks_minute+15*ticks_second+ticks_second/4;
|
||||
printf("setting current time\n");
|
||||
while (time<current_time) {
|
||||
if (time+ticks_hour<=current_time) { // first set hours
|
||||
time += ticks_hour; // increment hours
|
||||
} else if (time+ticks_minute<=current_time) { // second set minutes
|
||||
time += ticks_minute; // increment minutes
|
||||
} else if (time+ticks_minute<=current_time) { // third set seconds
|
||||
time += ticks_second; // increment seconds
|
||||
} else { // finally set time
|
||||
time = current_time;
|
||||
}
|
||||
clock_show_time(time); // set time (progress)
|
||||
leds_set(); // set the colors of all LEDs
|
||||
ws2812b_transmit(); // transmit set color
|
||||
time += 10;
|
||||
// delay some time
|
||||
for (uint32_t i=0; i<400000; i++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
|
||||
printf("input commands\n");
|
||||
bool action = false; // if an action has been performed don't go to sleep
|
||||
button_flag = false; // reset button flag
|
||||
char c; // to store received character
|
||||
@ -260,16 +279,11 @@ int main(void)
|
||||
action = true; // action has been performed
|
||||
printf("%c",c); // echo receive character
|
||||
|
||||
if (clear) {
|
||||
clock_clear(); // clear clock LEDs
|
||||
} else {
|
||||
printf("%02lu:%02lu\n", time/ticks_hour, (time%ticks_hour)/ticks_minute);
|
||||
clock_hour(time); // set time
|
||||
time += 1; // increment time
|
||||
}
|
||||
printf("%02lu:%02lu\n", time/ticks_hour, (time%ticks_hour)/ticks_minute);
|
||||
clock_show_time(time); // set time
|
||||
time += ticks_minute; // increment time
|
||||
leds_set(); // set the colors of all LEDs
|
||||
ws2812b_transmit(); // transmit set color
|
||||
clear = false;
|
||||
}
|
||||
while (button_flag) {
|
||||
button_flag = false; // reset flag
|
||||
|
Loading…
Reference in New Issue
Block a user