Test program for my Multi_WS2811 library that started out as a fork of heroic/WS2811. My library uses hardware DMA on the FRDM-KL25Z to drive up to 16 strings of WS2811 or WS2812 LEDs in parallel.
Dependencies: Multi_WS2811 mbed MMA8451Q
Fork of WS2811 by
NOTE: I have accidentally pushed changes for another fork of this program that I used in the recent Georgetown Carnival Power Tool Races. When I get some time, I will restore the test program to its original glory.
You can see my power tool racer (Nevermore's Revenge) here

This tests my FRDM-KL25Z multi-string WS2811/WS2812 library. It uses the accelerometer to change the rainbow phase on two strings of LEDs as well as the touch sense to change brightness.
A video of this program in operation is here.
Here is the library that I developed to run the LEDs:
Import libraryMulti_WS2811
Library allowing up to 16 strings of 60 WS2811 or WS2812 LEDs to be driven from a single FRDM-KL25Z board. Uses hardware DMA to do a full 800 KHz rate without much CPU burden.
Diff: Colors.cpp
- Revision:
- 31:c9eee3a33826
- Parent:
- 30:52e9205a8059
- Child:
- 32:115032de785f
--- a/Colors.cpp Sat Jan 04 00:32:16 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-#include <math.h>
-#include <mbed.h>
-#include "Colors.h"
-
-void HSBtoRGB(float hue, float saturation, float brightness, uint8_t *pr, uint8_t *pg, uint8_t *pb)
-{
- uint8_t r = 0, g = 0, b = 0;
- if (saturation == 0) {
- r = g = b = (uint8_t) (brightness * 255.0f + 0.5f);
- } else {
- float h = (hue - (float)floor(hue)) * 6.0f;
- float f = h - (float)floor(h);
- float p = brightness * (1.0f - saturation);
- float q = brightness * (1.0f - saturation * f);
- float t = brightness * (1.0f - (saturation * (1.0f - f)));
- switch ((int) h) {
- case 0:
- r = (int) (brightness * 255.0f + 0.5f);
- g = (int) (t * 255.0f + 0.5f);
- b = (int) (p * 255.0f + 0.5f);
- break;
- case 1:
- r = (int) (q * 255.0f + 0.5f);
- g = (int) (brightness * 255.0f + 0.5f);
- b = (int) (p * 255.0f + 0.5f);
- break;
- case 2:
- r = (int) (p * 255.0f + 0.5f);
- g = (int) (brightness * 255.0f + 0.5f);
- b = (int) (t * 255.0f + 0.5f);
- break;
- case 3:
- r = (int) (p * 255.0f + 0.5f);
- g = (int) (q * 255.0f + 0.5f);
- b = (int) (brightness * 255.0f + 0.5f);
- break;
- case 4:
- r = (int) (t * 255.0f + 0.5f);
- g = (int) (p * 255.0f + 0.5f);
- b = (int) (brightness * 255.0f + 0.5f);
- break;
- case 5:
- r = (int) (brightness * 255.0f + 0.5f);
- g = (int) (p * 255.0f + 0.5f);
- b = (int) (q * 255.0f + 0.5f);
- break;
- }
- }
- *pr = r;
- *pg = g;
- *pb = b;
-}
-
-float* RGBtoHSB(uint8_t r, uint8_t g, uint8_t b, float* hsbvals)
-{
- float hue, saturation, brightness;
- if (!hsbvals) {
- hsbvals = new float[3];
- }
- uint8_t cmax = (r > g) ? r : g;
- if (b > cmax) cmax = b;
- uint8_t cmin = (r < g) ? r : g;
- if (b < cmin) cmin = b;
-
- brightness = ((float) cmax) / 255.0f;
- if (cmax != 0)
- saturation = ((float) (cmax - cmin)) / ((float) cmax);
- else
- saturation = 0;
- if (saturation == 0)
- hue = 0;
- else {
- float redc = ((float) (cmax - r)) / ((float) (cmax - cmin));
- float greenc = ((float) (cmax - g)) / ((float) (cmax - cmin));
- float bluec = ((float) (cmax - b)) / ((float) (cmax - cmin));
- if (r == cmax)
- hue = bluec - greenc;
- else if (g == cmax)
- hue = 2.0f + redc - bluec;
- else
- hue = 4.0f + greenc - redc;
- hue = hue / 6.0f;
- if (hue < 0)
- hue = hue + 1.0f;
- }
- hsbvals[0] = hue;
- hsbvals[1] = saturation;
- hsbvals[2] = brightness;
- return hsbvals;
-}
Ned Konz


Generic WS2811/WS2812