Cycles through colors set in a buffer when the user button is pressed.

Dependencies:   PixelArray WS2812 mbed

Files at this revision

API Documentation at this revision

Comitter:
theros
Date:
Sat Mar 11 22:07:13 2017 +0000
Commit message:
First version.

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 d258c72c1ae2 PixelArray.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PixelArray.lib	Sat Mar 11 22:07:13 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/chris/code/PixelArray/#b45a70faaa83
diff -r 000000000000 -r d258c72c1ae2 WS2812.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WS2812.lib	Sat Mar 11 22:07:13 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/bridadan/code/WS2812/#6e647820f587
diff -r 000000000000 -r d258c72c1ae2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Mar 11 22:07:13 2017 +0000
@@ -0,0 +1,52 @@
+#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 btnState = 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) 
+    {
+        if (usrBtn == 0)    //button is pressed
+        { 
+            usrLed = 1;
+            btnState = btnState++;
+            
+            if (btnState == NUM_COLORS) {
+                btnState = 0;
+            }
+        } 
+        else 
+        {
+            usrLed = 0;
+        }
+        
+        //write the color value for each pixel
+        px.SetAll(colorbuf[btnState]);
+        
+        //write the II value for each pixel
+        px.SetAllI(64);
+        
+        for (int i = WS2812_BUF; i >= 0; i--) 
+        {
+            ws.write(px.getBuf());
+        }
+    }
+}
diff -r 000000000000 -r d258c72c1ae2 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Mar 11 22:07:13 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90
\ No newline at end of file