#include "rgbstring.h"
-static volatile uint16_t jiffies;
-
// #define CHRISTMAS_TREE 1
#define rgb_return(r, g, b) do { send_rgb((r), (g), (b)); return 1; } while(0)
ISR(ADC_vect) {
ADCSRA |= _BV(ADSC);
- jiffies++;
if ((rand_pool_off & 1) == 0) { // first bit of the pair
prev_bit = ADCW & 1;
rand_pool_off++;
prev_len = 0;
}
+#define LED_MAX (2*STRIP_SIZE/5)
+#define N_COLORS 8
+#define R_BIAS(x) ((x) << 3)
+#define G_BIAS(x) ((x) >> 1)
+#define B_BIAS(x) ((x) << 1)
+
+static void do_hue()
+{
+ static unsigned char color, led_off;
+ static uint16_t jiffies;
+ unsigned char i, c0, l0;
+
+ if ((jiffies++ & 0x03f) == 0) {
+ if (++led_off >= LED_MAX) {
+ led_off = 0;
+ color++;
+ if (color >= 3*N_COLORS)
+ color = 0;
+ }
+ }
+
+ l0 = led_off;
+ c0 = color;
+
+ for (i = 0; i < STRIP_SIZE; i++) {
+ if (c0 < N_COLORS) {
+ send_rgb(R_BIAS(N_COLORS-c0), G_BIAS(c0), 0);
+ } else if (c0 < 2*N_COLORS) {
+ send_rgb(0, G_BIAS(2*N_COLORS-c0), B_BIAS(c0-N_COLORS));
+ } else {
+ send_rgb(R_BIAS(c0-2*N_COLORS), 0, B_BIAS(3*N_COLORS-c0));
+ }
+
+ if (++l0 >= LED_MAX) {
+ l0 = 0;
+ c0++;
+ if (c0 >= 3*N_COLORS)
+ c0 = 0;
+ }
+ }
+ end_frame();
+}
+
int main(void)
{
PORTB |= _BV(PB0) | _BV(PB3) | _BV(PB4); // pull-ups for buttons
- state = 0;
+ state = 2;
sei();
while (1) {
unsigned char i;
- static unsigned char c = 28;
do_buttons();
end_frame();
break;
case 2:
- if ((jiffies & 0x1ff) == 0) {
- c++;
- if (c >= 30)
- c = 0;
- }
-
- for (i = 0; i < STRIP_SIZE; i++) {
- unsigned char x = c; // + i / 2;
- if (x >= 30)
- x %= 30;
- if (x < 10) {
- send_rgb(8*(10-x), x, 0);
- } else if (x < 20) {
- send_rgb(0, 20-x, x-10);
- } else {
- send_rgb(8*(x-20), 0, 30-x);
- }
- }
- end_frame();
+ do_hue();
break;
case 3:
- fill_color(32, 4, 8);
+ fill_color(16, 4, 8);
break;
case 4:
- fill_color(255, 92, 92);
+ fill_color(96, 64, 64);
break;
case 5:
fill_color(255, 255, 255);