This is a bitbang library for WS2812. I test it with STM32F411RE (Nucleo 441RE). If you want to use another board, u need to adjust the sum of asm("nop"). In the example program i put some code to measure how many asm("nop") do we need. See more detail about WS2812 timing https://cdn-shop.adafruit.com/datasheets/WS2812.pdf

Dependents:   STM32FC_RGB_WS2812

Committer:
devararendy
Date:
Sat Dec 10 09:18:10 2016 +0000
Revision:
1:8910a1fcbdb0
Parent:
0:f080cb888db6
added sendColors function, for sending color buffer to all LEDs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
devararendy 0:f080cb888db6 1 #ifndef WS2812_H
devararendy 0:f080cb888db6 2 #define WS2812_H
devararendy 0:f080cb888db6 3 #include "mbed.h"
devararendy 0:f080cb888db6 4 #include "USBSerial.h"
devararendy 0:f080cb888db6 5
devararendy 0:f080cb888db6 6 class WS2812
devararendy 0:f080cb888db6 7 {
devararendy 0:f080cb888db6 8 public:
devararendy 0:f080cb888db6 9
devararendy 0:f080cb888db6 10 uint8_t Red;
devararendy 0:f080cb888db6 11 uint8_t Green;
devararendy 0:f080cb888db6 12 uint8_t Blue;
devararendy 0:f080cb888db6 13
devararendy 0:f080cb888db6 14 WS2812(PinName pin, int qty);
devararendy 0:f080cb888db6 15 ~WS2812();
devararendy 0:f080cb888db6 16 void writeColor(uint32_t RGB);
devararendy 0:f080cb888db6 17 void send1Color(uint32_t RGB);
devararendy 1:8910a1fcbdb0 18 void sendColors(uint32_t * ColorBuffer);
devararendy 0:f080cb888db6 19 void sendReset();
devararendy 0:f080cb888db6 20
devararendy 0:f080cb888db6 21 private:
devararendy 0:f080cb888db6 22 int LED_Qty;
devararendy 0:f080cb888db6 23 PinName dataPin;
devararendy 0:f080cb888db6 24 DigitalOut dataOut;
devararendy 0:f080cb888db6 25
devararendy 0:f080cb888db6 26 void writeByte(uint8_t data);
devararendy 0:f080cb888db6 27 void send0();
devararendy 0:f080cb888db6 28 void send1();
devararendy 0:f080cb888db6 29 };
devararendy 0:f080cb888db6 30
devararendy 0:f080cb888db6 31 #endif