Simple 8x8 LED Matrix controller which interfaces with a Processing GUI over serial to display sketches

Dependencies:   Multi_WS2811 mbed

Fork of Multi_WS2811_test by Ned Konz

Revision:
32:7b60b9add4b5
Parent:
30:52e9205a8059
Child:
33:7973b70d4fab
--- a/main.cpp	Sat Jan 04 00:45:20 2014 +0000
+++ b/main.cpp	Fri Nov 14 08:18:35 2014 +0000
@@ -60,18 +60,18 @@
     strip.show();
 }
 
-static void showSolidColor(WS2811 &strip, uint8_t r, uint8_t g, uint8_t b)
+static void clearScreen(WS2811 &strip)
 {
     unsigned nLEDs = strip.numPixels();
     for (unsigned i = 0; i < nLEDs; i++) {
-        strip.setPixelColor(i, r, g, b);
+        strip.setPixelColor(i, 0, 0, 0);
     }
     strip.show();
 }
 
 int main(void)
 {
-    pc.baud(115200);
+    pc.baud(9600);
     WS2811 lightStrip1(nLEDs, DATA_OUT_PIN1);
     WS2811 lightStrip2(nLEDs, DATA_OUT_PIN2);
 
@@ -84,44 +84,33 @@
 
     timeRunning.start();
 
-    uint8_t r =0;
-    uint8_t g =0;
-    uint8_t b =0;
+
+    uint8_t q = 0;
+    char char_buff[6];
     for (;;) {
-        if (r < 40)
-            r++;
-        else if (g < 40)
-            g++;
-        else if (b < 40)
-            b++;
-        else {
-            unsigned running = timeRunning.read_us();
-            pc.printf("%u frames in %u usec = %u frames / sec\r\n", frames, running, frames * 1000000 / running);
-            break;
+        if(pc.readable()){
+            if(pc.getc()==255){
+                while(q < 6){
+                    while(!pc.readable());
+                    char_buff[q] = pc.getc();
+                    pc.putc(char_buff[q]);
+                    if(char_buff[q] == 254)
+                        break;
+                    q++;
+                }
+
+                if(q >= 4){
+                    lightStrip1.setPixelColor(int(char_buff[0])+8*char_buff[1], int(char_buff[2]), int(char_buff[3]), int(char_buff[4]));                    
+                    lightStrip1.show();
+                }
+                else{
+                    clearScreen(lightStrip1);
+                }
+                q = 0;
+                WS2811::startDMA();
+            }    
         }
 
-        showSolidColor(lightStrip1, r, g, b);
-        showSolidColor(lightStrip2, r, g, b);
-        WS2811::startDMA();
-
-        frames++;
-    }
-
-    timeRunning.reset();
-    frames = 0;
-
-    float xyz[3];
-    acc.getAccAllAxis(xyz);
-    pc.printf("x: %f y: %f z: %f\r\n", xyz[0], xyz[1], xyz[2]);
-
-    for (;;) {
-        acc.getAccAllAxis(xyz);
-        rled = 1.0 - abs(xyz[0]);
-        gled = 1.0 - abs(xyz[1]);
-        readTouchSensor();
-        showRainbow(lightStrip1, sat, brite, abs(xyz[0]));
-        showRainbow(lightStrip2, sat, brite, abs(xyz[1]));
-        WS2811::startDMA();
 
         frames ++;
     }