Chris Styles / Mbed 2 deprecated ChrisRGB-Ring

Dependencies:   PixelArray WS2812 mbed

Files at this revision

API Documentation at this revision

Comitter:
chris
Date:
Mon Aug 18 13:27:10 2014 +0000
Parent:
0:6b847e039b3b
Child:
2:57db905622ca
Commit message:
Rotate buffer using offsets

Changed in this revision

PixelArray.lib Show annotated file Show diff for this revision Revisions of this file
WS2812.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/PixelArray.lib	Wed Aug 06 09:34:24 2014 +0000
+++ b/PixelArray.lib	Mon Aug 18 13:27:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/chris/code/PixelArray/#41b9f8ec0b6a
+http://mbed.org/users/chris/code/PixelArray/#b45a70faaa83
--- a/WS2812.lib	Wed Aug 06 09:34:24 2014 +0000
+++ b/WS2812.lib	Mon Aug 18 13:27:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/chris/code/WS2812/#b230e85fc5e7
+http://mbed.org/users/chris/code/WS2812/#a07522fe36d4
--- a/main.cpp	Wed Aug 06 09:34:24 2014 +0000
+++ b/main.cpp	Mon Aug 18 13:27:10 2014 +0000
@@ -7,37 +7,51 @@
 WS2812 ws(p5,WS2812_BUF);
 PixelArray px(WS2812_BUF);
 
+DigitalOut led(LED1);
+
 int main()
 {
 
+    int ctr=0;
     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++) {
+    int h=0;
 
-            // 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);
+    // 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)));
+    }
+
+    // the buffer is written
+    // rotate by writing it out with an increasing offset
+
+
+    while (1) {
+        for (int z=59; z >= 0 ; z--) {
+            ws.write_offsets(px.getBuf(),z,z,z); // write out the buffer
+            wait(0.075);
+            if (ctr==1000) {
+                ctr=0;
+                led=!led;
+            } else {
+                ctr++;
+            }
+        }
+    }
+
 }