]> www.fi.muni.cz Git - tinyboard.git/blobdiff - projects/rgb-led-string/main.c
rgb-led-string: single-direction white stars
[tinyboard.git] / projects / rgb-led-string / main.c
index 4c82f48b8f2bed6b97f3c74e471495b60aec8d56..dc968613c6d85b9878405e13dd712f9e06d1b086 100644 (file)
@@ -4,17 +4,86 @@
 
 #include "rgbstring.h"
 
+unsigned char jiffies;
+
+typedef struct {
+       unsigned char type : 4;
+       unsigned char order : 4;
+} pixel_t;
+
+pixel_t pixels[STRIP_SIZE];
+
+
 int main(void)
 {
+       unsigned char i, start, rgb, jiffies;
        init_log();
+       init_serial();
+
+       _delay_ms(3000/8);
+       CLKPR = _BV(CLKPCE);
+       CLKPR = 0;
 
-       log_set_state(3);
+       for (i = 0; i < STRIP_SIZE; i+= 23)
+               pixels[i].type = 2;
 
-       DDRB |= _BV(PB2);
        while (1) {
-               PORTB |=  _BV( PB2 );
-               _delay_ms(200);
-               PORTB &=~ _BV( PB2 );
-               _delay_ms(200);
+               jiffies++;
+               if ((jiffies & 7) == 0) {
+                       pixels[start].type = 1;
+                       pixels[start].order = 14;
+               }
+
+               if ((jiffies & 7) == 3) {
+                       pixels[start].type = 2;
+                       pixels[start].order = 0;
+                       start += 19;
+               }
+
+               start += 63;
+               if (start >= STRIP_SIZE)
+                       start -= STRIP_SIZE;
+
+               for (i = 0; i < STRIP_SIZE; i++) {
+                       unsigned char type = pixels[i].type;
+                       unsigned char order = pixels[i].order;
+
+                       switch (type) {
+                       case 0:
+                               send_rgb(0, 0, 4);
+                               break;
+                       case 1:
+                       case 3:
+                               send_rgb(
+                                       6+(1 << (order/2)),
+                                       6+(1 << (order/2)),
+                                       6+(1 << (order/2))
+                               );
+                               pixels[i].type = type == 3 ? 2 : 0;;
+                               if (order > 1 && i) {
+                                       pixels[i-1].type = pixels[i-1].type == 2 ? 3 : 1;
+                                       pixels[i-1].order = order-1;
+                               }
+                               break;
+                       case 2:
+                               if (order >= 8) {
+                                       send_rgb(1 << ((15-order) / 2), 0, 0);
+                               } else {
+                                       send_rgb(1 << (order/2), 0, 0);
+                               }
+                               if (++order >= 15)
+                                       pixels[i].type = 0;
+                               pixels[i].order = order;
+                               break;
+                       }
+               }
+
+               end_frame();
+
+               _delay_ms(50);
+#if 0
+               log_byte(0xFa);
+               log_flush();
+#endif
        }
 }