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)
{
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
if (led_hour<WS2812B_LEDS) {
clock_leds[led_hour*3+0] = 0;
clock_leds[led_hour*3+1] = 0;
clock_leds[led_hour*3+2] = 0xff;
uint32_t led_hour = (WS2812B_LEDS*(255*(uint64_t)(time)))/ticks_midday; // scale to LED brightnesses
printf("led hour: %lu, brightness: %lu\n", led_hour/255, led_hour%255);
if (led_hour>=WS2812B_LEDS*255) { // a calculation error occurred
return;
}
/*
for (uint16_t led=0; led<hour; led++) {
for (uint16_t led=0; led<WS2812B_LEDS && led_hour>0; led++) {
clock_leds[led*3+0] = 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 */
@ -168,14 +170,15 @@ int main(void)
#endif
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
led_on(); // switch on LED to indicate setup completed
clock_hour(6*ticks_hour);
leds_set(); // set the colors of all LEDs
ws2812b_transmit(); // transmit set color
uint32_t time = 0; // the time to display
bool clear = true; // clear or display time
bool action = false; // if an action has been performed don't go to sleep
button_flag = false; // reset button flag
@ -199,34 +202,17 @@ int main(void)
char_flag = false; // reset flag
action = true; // action has been performed
printf("%c",c); // echo receive character
switch (c) {
case 'r': // set red color
clock_leds[0] = 0xff;
clock_leds[1] = 0;
clock_leds[2] = 0;
break;
case 'g': // set green color
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;
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 += 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