show hour time with gradient

This commit is contained in:
King Kévin 2016-02-23 20:28:55 +01:00
parent 45c5b1252f
commit 02658f2c45
1 changed files with 24 additions and 38 deletions

62
main.c
View File

@ -118,19 +118,21 @@ static void clock_hours(void)
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 time %= ticks_midday; // the LED strip can only display 12 hours
uint32_t led_hour = WS2812B_LEDS*time/ticks_midday; // scale to number of LEDs uint32_t led_hour = (WS2812B_LEDS*(255*(uint64_t)(time)))/ticks_midday; // scale to LED brightnesses
if (led_hour<WS2812B_LEDS) { printf("led hour: %lu, brightness: %lu\n", led_hour/255, led_hour%255);
clock_leds[led_hour*3+0] = 0; if (led_hour>=WS2812B_LEDS*255) { // a calculation error occurred
clock_leds[led_hour*3+1] = 0; return;
clock_leds[led_hour*3+2] = 0xff;
} }
/* for (uint16_t led=0; led<WS2812B_LEDS && led_hour>0; led++) {
for (uint16_t led=0; led<hour; 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;
clock_leds[led*3+2] = 0xff; if (led_hour>=0xff) { // full hours
clock_leds[led*3+2] = 0xff;
} else { // running hours
clock_leds[led*3+2] = led_hour;
}
led_hour -= clock_leds[led*3+2];
} }
*/
} }
/* set the LEDs */ /* set the LEDs */
@ -168,14 +170,15 @@ int main(void)
#endif #endif
ws2812b_setup(); // setup WS2812b LEDs ws2812b_setup(); // setup WS2812b LEDs
clock_clear(); // clear clock LEDs clock_hours(); // show hour markers
leds_set(); // set the colors of all LEDs
ws2812b_transmit(); // transmit set color
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
led_on(); // switch on LED to indicate setup completed led_on(); // switch on LED to indicate setup completed
clock_hour(6*ticks_hour); uint32_t time = 0; // the time to display
leds_set(); // set the colors of all LEDs bool clear = true; // clear or display time
ws2812b_transmit(); // transmit set color
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
@ -199,34 +202,17 @@ int main(void)
char_flag = false; // reset flag char_flag = false; // reset flag
action = true; // action has been performed action = true; // action has been performed
printf("%c",c); // echo receive character printf("%c",c); // echo receive character
switch (c) {
case 'r': // set red color if (clear) {
clock_leds[0] = 0xff; clock_clear(); // clear clock LEDs
clock_leds[1] = 0; } else {
clock_leds[2] = 0; printf("%02lu:%02lu\n", time/ticks_hour, (time%ticks_hour)/ticks_minute);
break; clock_hour(time); // set time
case 'g': // set green color time += ticks_minute; // increment time
clock_leds[0] = 0;
clock_leds[1] = 0xff;
clock_leds[2] = 0;
break;
case 'b': // set blue color
clock_leds[0] = 0;
clock_leds[1] = 0;
clock_leds[2] = 0xff;
break;
case 'm': // show hour marks
clock_hours();
break;
case 'h': // show hours
clock_hour(6*ticks_hour);
break;
default: // set no color
clock_clear();
break;
} }
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
clear = false;
} }
while (button_flag) { while (button_flag) {
button_flag = false; // reset flag button_flag = false; // reset flag