1

Dependencies:   PixelArray WS2812 mbed

Files at this revision

API Documentation at this revision

Comitter:
yu10078999
Date:
Wed Sep 07 14:20:53 2016 +0000
Commit message:
0

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2024cf2d17f8 PixelArray.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PixelArray.lib	Wed Sep 07 14:20:53 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/chris/code/PixelArray/#b45a70faaa83
diff -r 000000000000 -r 2024cf2d17f8 WS2812.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WS2812.lib	Wed Sep 07 14:20:53 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/bridadan/code/WS2812/#6e647820f587
diff -r 000000000000 -r 2024cf2d17f8 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 07 14:20:53 2016 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#include "WS2812.h"
+#include "PixelArray.h"
+
+#define WS2812_BUF 150
+#define NUM_COLORS 6
+#define NUM_LEDS_PER_COLOR 3
+
+PixelArray px(WS2812_BUF);
+
+// See the program page for information on the timing numbers
+// The given numbers are for the K64F
+WS2812 ws(D9, WS2812_BUF, 10, 15, 20, 25);
+//WS2812 ws(D9, WS2812_BUF, 10, 15, 20, 35);
+int main()
+{
+
+    ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
+    
+    // set up the colours we want to draw with
+    int colorbuf[NUM_COLORS] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f};
+
+    // for each of the colours (j) write out 10 of them
+    // the pixels are written at the colour*10, plus the colour position
+    // all modulus 60 so it wraps around
+    for (int i = 0; i < WS2812_BUF; i++) {
+        px.Set(i, colorbuf[(i / NUM_LEDS_PER_COLOR) % NUM_COLORS]);
+    }
+
+    // now all the colours are computed, add a fade effect using intensity scaling
+    // compute and write the II value for each pixel
+    for (int j=0; j<WS2812_BUF; j++) {
+        // px.SetI(pixel position, II value)
+        px.SetI(j%WS2812_BUF, 0xf+(0xf*(j%NUM_LEDS_PER_COLOR)));
+    }
+
+
+    // Now the buffer is written, rotate it
+    // by writing it out with an increasing offset
+    while (1) {
+        for (int z=WS2812_BUF; z >= 0 ; z--) {
+            ws.write_offsets(px.getBuf(),z,z,z);
+            wait(0.075);
+        }
+    }
+
+}
diff -r 000000000000 -r 2024cf2d17f8 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 07 14:20:53 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897
\ No newline at end of file