![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
WS2812 example
Dependencies: WS2812_LED mbed
Fork of WS2812-Example by
Revision 0:52571581ff7e, committed 2015-11-18
- Comitter:
- fastestoffer
- Date:
- Wed Nov 18 18:11:40 2015 +0000
- Commit message:
- Initial commit of example;
Changed in this revision
diff -r 000000000000 -r 52571581ff7e WS2812_LED.lib --- /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
diff -r 000000000000 -r 52571581ff7e main.cpp --- /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
diff -r 000000000000 -r 52571581ff7e mbed.bld --- /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