Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PixelArray WS2812 mbed
Diff: main.cpp
- Revision:
- 0:12cb6f0c2788
- Child:
- 1:e04a0ecefa29
diff -r 000000000000 -r 12cb6f0c2788 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Feb 12 19:20:00 2015 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "WS2812.h"
+#include "PixelArray.h"
+
+#define WS2812_BUF 60
+
+WS2812 ws(D9,WS2812_BUF);
+PixelArray px(WS2812_BUF);
+
+DigitalOut led(LED1);
+
+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};
+
+ // 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<6; i++) {
+ for (int j=0; j<10; j++) {
+ px.Set(((i*10)+j)%60,colorbuf[i]);
+ }
+ }
+
+ // 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<60; j++) {
+ // px.SetI(pixel position, II value)
+ px.SetI(j%60, 0xf+(0xf*(j%10)));
+ }
+
+
+ // Now the buffer is written, rotate it
+ // 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);
+ wait(0.075);
+ }
+ }
+
+}
Generic WS2812 Driver