![](/media/cache/profiles/493c8b3821e768713a4d1c5b1e7f5ad4.jpg.50x50_q85.png)
miniblip demo program
Fork of NeoPixel Demo by
Diff: main.cpp
- Revision:
- 1:ca76237d2965
- Parent:
- 0:60499ad28ea9
- Child:
- 3:2d84c8262139
diff -r 60499ad28ea9 -r ca76237d2965 main.cpp --- a/main.cpp Fri Jul 25 15:22:59 2014 +0000 +++ b/main.cpp Fri Aug 01 22:43:26 2014 +0000 @@ -1,28 +1,30 @@ #include "mbed.h" -#include "neopixel-spi.h" +#include "neopixel.h" -// A backing store for the pixel data. -static size_t const count = 16; -neopixel::Pixel pixels[count]; +// This must be an SPI MOSI pin. +#define DATA_PIN p5 -// The pixel array control class. -neopixel::Array array(p30); - -uint8_t IntensityForIndex(size_t index) { - uint32_t c = index % 512; - return (c >= 256) ? (256 - c) : c; +void generate(neopixel::Pixel * out, uint32_t index, uintptr_t extra) +{ + uint32_t brightness = (index + extra) >> 3; + out->red = ((index + extra) & 0x1) ? brightness : 0; + out->green = ((index + extra) & 0x2) ? brightness : 0; + out->blue = ((index + extra) & 0x4) ? brightness : 0; } -int main() { - size_t offset = 0; - while (1) { - for (size_t i = 0; i < count; i++) { - pixels[i].red = IntensityForIndex((i * 10) + offset); - pixels[i].green = IntensityForIndex((i * 20) + offset); - pixels[i].blue = IntensityForIndex((i * 40) + offset); +int main() +{ + // Create a temporary DigitalIn so we can configure the pull-down resistor. + // (The mbed API doesn't provide any other way to do this.) + // An alternative is to connect an external pull-down resistor. + DigitalIn(DATA_PIN, PullDown); + + // The pixel array control class. + neopixel::PixelArray array(DATA_PIN); + + uint32_t offset = 0; + while (1) { + array.update(generate, 100, offset++); + wait_ms(250); } - array.Update(pixels, count); - wait_ms(10); - offset++; - } }