From 9747b98dfb674133f4cec640adecce681b8428af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 23 Feb 2016 23:56:04 +0100 Subject: [PATCH] also show seconds --- main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 35285c0..0acf287 100644 --- a/main.c +++ b/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_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 return; } @@ -174,6 +173,16 @@ static void clock_hour(uint32_t time) 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 */ @@ -221,6 +230,13 @@ int main(void) uint32_t time = 0; // the time to display 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 button_flag = false; // reset button flag char c; // to store received character @@ -249,7 +265,7 @@ int main(void) } else { printf("%02lu:%02lu\n", time/ticks_hour, (time%ticks_hour)/ticks_minute); clock_hour(time); // set time - time += ticks_minute; // increment time + time += 1; // increment time } leds_set(); // set the colors of all LEDs ws2812b_transmit(); // transmit set color