WS2812 example

Dependencies:   WS2812_LED mbed

Fork of WS2812-Example by Maximilian Erlbeck

Files at this revision

API Documentation at this revision

Comitter:
fastestoffer
Date:
Wed Nov 18 18:11:40 2015 +0000
Commit message:
Initial commit of example;

Changed in this revision

WS2812_LED.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WS2812_LED.lib	Wed Nov 18 18:11:40 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/silabs-abakurs/code/WS2812_LED/#f1e39d76fbca
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 18 18:11:40 2015 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+#include "WS2812.h"
+
+LowPowerTicker toggleTicker;
+
+Color color_red = {255, 0, 0};
+Color color_green = {0, 255, 0};
+Color color_blue = {0, 0, 255};
+Color color_black = {0,0,0};
+
+bool update_led_flag;
+bool ledstrip_busy;
+int state = 0;
+
+void update(void) {
+    update_led_flag = true;
+}
+
+void send_complete(int event) {
+    (void)event;
+    ledstrip_busy = false;
+}
+
+event_callback_t callback;
+
+int main(void) {
+
+    SPI spi(PE10, NC, PE12);
+    
+    callback.attach(send_complete);
+    
+    WS2812 ledstrip(spi, callback);
+    
+    toggleTicker.attach(&update, 1.0f);
+
+    while(1) {
+        sleep();
+        if(update_led_flag)
+        {
+            update_led_flag=false;
+            switch(state){
+                case 0:
+                    ledstrip.set_all(&color_green);
+                    state++;
+                    break;
+                case 1:
+                    ledstrip.set_all(&color_blue);
+                    state++;
+                    break;
+                case 2:
+                    ledstrip.set_all(&color_red);
+                    state=0;
+                    break;
+            }
+            ledstrip_busy = true;
+            ledstrip.update_strip();
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 18 18:11:40 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file