A program that fades between a selection of colors.

Dependencies:   PixelArray WS2812 mbed

Revision:
0:de636c7cdfda
Child:
1:ad5c2cfb2002
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 12 14:56:52 2017 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#include "WS2812.h"
+#include "PixelArray.h"
+
+#define WS2812_BUF 77   //number of LEDs in the array
+#define NUM_COLORS 6    //number of colors to store in the array
+
+DigitalIn usrBtn(USER_BUTTON);
+DigitalOut usrLed(LED1);
+PixelArray px(WS2812_BUF);
+
+// See the program page for information on the timing numbers
+WS2812 ws(D9, WS2812_BUF, 6,17,9,14);   //nucleo-f411re
+
+int main()
+{
+    int colorIdx = 0;
+    
+    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};
+    
+    // Now the buffer is written, write it to the led array.
+    while (1) 
+    {
+        //write the color value for each pixel
+        px.SetAll(colorbuf[colorIdx]);
+        
+        //write the II value for each pixel
+        px.SetAllI(64);
+        
+        for (int i = WS2812_BUF; i >= 0; i--) 
+        {
+            ws.write(px.getBuf());
+        }
+        
+        colorIdx++;
+        
+        if (colorIdx >= NUM_COLORS)
+        {
+            colorIdx = 0;
+        }
+    }
+}