Aamir Niaz
/
mbed_ws2812b
ws2812b
Fork of mbed_ws2812b by
Diff: main.cpp
- Revision:
- 0:afb6ebe20c1f
- Child:
- 1:d9c6619240a3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Dec 13 06:58:47 2014 +0000 @@ -0,0 +1,64 @@ +/* + + Neopixel LED controller for mbed LPC1114 (RAMdaccha) + + 2014/12/13 by morecat_lab + + This program depends on neopixel library. + http://developer.mbed.org/users/JacobBramley/code/PixelArray/ + +*/ +#include "mbed.h" +#include "neopixel.h" +#include "LAMd.h" + +neopixel::Pixel pattern[] = { + {0x55, 0, 0xff}, // magenta + {0, 0, 0xff}, // blue + {0xaf, 0xaf, 0xaf}, // white + {0, 0xff, 0xff}, // cyan + {0xaf, 0xaf, 0}, // yellow + {0, 0xff, 0}, // greem + {0x2f, 0, 0}, // red +}; + +#define MAX_PATTERN (sizeof pattern / sizeof (struct neopixel::Pixel)) +#define MAX_INDEX (MAX_PATTERN *256) +#define NLED (4) +#define ONE_COLOR + + void generate(neopixel::Pixel * out, uint32_t index, uintptr_t val) { +#ifdef ONE_COLOR + uint32_t pat1 = val / 256; +#else + uint32_t pat1 = val / 256 + index; +#endif + uint32_t pat2; + uint32_t seq = val % 256; + + if (pat1 >= MAX_PATTERN) { + pat1 = 0; + } + pat2 = pat1 + 1; + if (pat2 >= MAX_PATTERN) { + pat2 = 0; + } + out->red = (pattern[pat1].red * (256-seq) + pattern[pat2].red * seq) /256; + out->green = (pattern[pat1].green * (256-seq) + pattern[pat2].green * seq) /256; + out->blue = (pattern[pat1].blue * (256-seq) + pattern[pat2].blue * seq) /256; + } + + +int main() { + DigitalIn(D3, PullDown); + neopixel::PixelArray array(D3); + + uint32_t val = 0; + while (1) { + if ((++val) >= MAX_INDEX) { + val = 0; + } + array.update(generate, NLED, val); + wait_ms(10); + } +}