Experimental WS2812 driver and pixel buffer

Dependencies:   PixelArray WS2812 mbed

Revision:
0:6b847e039b3b
Child:
1:bf4d674d3692
diff -r 000000000000 -r 6b847e039b3b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 06 09:34:24 2014 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "WS2812.h"
+#include "PixelArray.h"
+
+#define WS2812_BUF 60
+
+WS2812 ws(p5,WS2812_BUF);
+PixelArray px(WS2812_BUF);
+
+int main()
+{
+
+    ws.useII(2); // use per-pixel intensity scaling
+
+    // set up the colours we want to draw with
+    int colorbuf[6] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f};
+
+    while(1) {
+
+        // h is the starting point, incrementing makes the rendered buffer rotate
+        for (int h=0; h<60; h++) {
+
+            // for each of the colours (j) write out 10 of them
+            // the pixel get written at the rotation offset, plus the colour*10, plus the colour position
+            // all modulus 60 so it wraps around
+            for (int i =0; i<6; i++) {
+                for (int j=0; j<10; j++) {
+                    px.Set((h+(i*10)+j)%60,colorbuf[i]);
+                }
+            }
+
+            // now all the colours are computed, add a fade effect
+            // compute and write the II value for each pixel
+            for (int j=0; j<60; j++) {
+                // px.SetI(pixel position, II value)
+                px.SetI(    (h+j)%60,   0xf+(0xf*(j%10)));
+            }
+
+            ws.write(px.getBuf()); // write out the buffer
+            wait(0.05);
+        }
+    }
+}