diff --git a/Makefile b/Makefile index e3ade60..2419611 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PRG = rgbyteclock -OBJ = rgbyteclock.o timer.o lcd.o main.o rtc.o spi.o ringbuffer.o crc.o ledcontroller.o +OBJ = rgbyteclock.o timer.o lcd.o main.o rtc.o spi.o ringbuffer.o crc.o ledcontroller.o rgbyteclock_patterns.o MCU_TARGET = atmega164a OPTIMIZE = -Os @@ -25,7 +25,8 @@ $(PRG).elf: $(OBJ) @echo # dependency: -rgbyteclock.o: timer.o lcd.o rgbyteclock.h rtc.o spi.o ledcontroller.o +rgbyteclock_patterns.o: timer.o lcd.o rgbyteclock_patterns.h rtc.o spi.o ledcontroller.o +rgbyteclock.o: rgbyteclock_patterns.o main.o: rgbyteclock.o lcd.o spi.o ledcontroller.o rtc.o timer.o timer.o: timer.h lcd.o: lcd.h timer.o diff --git a/rgbyteclock.c b/rgbyteclock.c index cfba909..0753a52 100644 --- a/rgbyteclock.c +++ b/rgbyteclock.c @@ -1,13 +1,11 @@ #include "rgbyteclock.h" -#include "timer.h" -#include "rtc.h" -#include "lcd.h" -#include "ledcontroller.h" void rgbyteclock(void) { + + rgbyteclock_rounds_colored(); while (1) { diff --git a/rgbyteclock.h b/rgbyteclock.h index 9d1c6f4..b159aa2 100644 --- a/rgbyteclock.h +++ b/rgbyteclock.h @@ -15,6 +15,11 @@ #include +#include "timer.h" +#include "rtc.h" +#include "lcd.h" +#include "ledcontroller.h" +#include "rgbyteclock_patterns.h" void rgbyteclock(void); diff --git a/rgbyteclock_patterns.c b/rgbyteclock_patterns.c new file mode 100644 index 0000000..bab1fd6 --- /dev/null +++ b/rgbyteclock_patterns.c @@ -0,0 +1,176 @@ + +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. + * (c) 2014 Stefan Rupp + * ---------------------------------------------------------------------------- + */ + + +#include "timer.h" +#include "rtc.h" +#include "lcd.h" +#include "ledcontroller.h" + + +enum { LED_OFF, LED_GLOW, LED_S0, LED_S1, LED_S2, LED_S3, LED_S4, LED_S5}; +uint16_t led_values[] = {0x00, 0x00cf, 0x00, 0x04ff, 0x08ff, 0x10ff, 0x20ff}; + + +void rgbyteclock_rounds(void) +{ + + led_turn_all_on(); + + while (1) { + //PORTC ^= (1< 2) { color_start = 0; } + color = color_start; + for (int led=0; led<12; led++) { + color++; + switch (color) { + case 1: + led_set(led, 0x00, brightness, 0x00); + break; + case 2: + led_set(led, 0x00, 0x00, brightness); + break; + default: + color = 0; + led_set(led, brightness, 0x00, 0x00); + break; + } + led_flush(); + timer_wait(5); + } + brightness = brightness + brightness/20; + if (brightness > 0x4fff) { + brightness = 0xff; + } + + } +} + +void rgbyteclock_secwatch(void) +{ + uint8_t hours, mins; + + uint32_t t, t_last=0; + + led_turn_all_on(); + + while (1) { + t = timer_get()/1000; + if (t != t_last) { + t_last = t; + mins = t%60; + hours = t/60; + uint8_t l_mins = mins/5; + uint8_t l_hours = hours/5; + led_clear(); + if (l_mins != l_hours) { + led_set(l_mins, 0, 0x7ff, 0); + led_set(l_hours, 0, 0, 0x7ff); + } + else { + led_set(l_mins, 0, 0x7ff, 0x7ff); + } + led_flush(); + } + } +} + +void rgbyteclock_secwatch_glide(void) +{ + uint8_t hours, mins; + + uint32_t t, t_last=0; + + led_turn_all_on(); + + while (1) { + t = rtc_get(); + if (t != t_last) { + t_last = t; + mins = t%60; + hours = t/60; + uint8_t l_mins = mins/5; + uint8_t l_hours = hours/5; + uint8_t l_mins_next = l_mins+1; + uint8_t l_hours_next = l_hours+1; + + if (l_mins_next > 11) { l_mins_next = 0; } + if (l_hours_next > 11) { l_hours_next = 0; } + + uint16_t d_m1, d_m2; + uint16_t d_h1, d_h2; + + /* + d_m2 = ((mins%5)*d_bright)/4; + d_h2 = ((hours%5)*d_bright)/4; + d_m1 = ((4-(mins%5))*d_bright)/4; + d_h1 = ((4-(hours%5))*d_bright)/4; + */ + d_m2 = led_values[(mins%5)+2]; + d_h2 = led_values[(hours%5)+2]; + d_m1 = led_values[4-(mins%5)+2]; + d_h1 = led_values[4-(hours%5)+2]; + uint16_t d_dark = led_values[1]; + + led_clear(); + for (int led=0;led<12;led++) { + led_set(led, d_dark, 0, 0); + } + if (l_mins != l_hours) { + led_set(l_mins, d_dark, d_m1, 0); + led_set(l_hours, d_dark, 0, d_h1); + led_set(l_mins_next, d_dark, d_m2, 0); + led_set(l_hours_next, d_dark, 0, d_h2); + } + else { + led_set(l_mins, 0xf, d_m1, d_h1); + led_set(l_mins_next, 0xf, d_m2, d_h2); + } + led_flush(); + } + } +} + diff --git a/rgbyteclock_patterns.h b/rgbyteclock_patterns.h new file mode 100644 index 0000000..e550db8 --- /dev/null +++ b/rgbyteclock_patterns.h @@ -0,0 +1,27 @@ + +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. + * (c) 2014 Stefan Rupp + * ---------------------------------------------------------------------------- + */ + +#ifndef RGBYTECLOCK_PATTERNS_H_ +#define RGBYTECLOCK_PATTERNS_H_ + +#include "rgbyteclock.h" +#include "timer.h" +#include "rtc.h" +#include "lcd.h" +#include "ledcontroller.h" + + +void rgbyteclock_rounds(void); +void rgbyteclock_rounds_colored(void); +void rgbyteclock_secwatch(void); +void rgbyteclock_secwatch_glide(void); + +#endif