Demo application for Adafruit NeoPixels.

Dependencies:   PixelArray mbed

Committer:
JacobBramley
Date:
Thu Mar 12 09:42:54 2015 +0000
Revision:
2:b70964f8a427
Parent:
1:ca76237d2965
Replace the "neopixel-spi" library with "PixelArray". (It is the same thing, but was renamed some time ago.)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JacobBramley 0:60499ad28ea9 1 #include "mbed.h"
JacobBramley 1:ca76237d2965 2 #include "neopixel.h"
JacobBramley 0:60499ad28ea9 3
JacobBramley 1:ca76237d2965 4 // This must be an SPI MOSI pin.
JacobBramley 1:ca76237d2965 5 #define DATA_PIN p5
JacobBramley 0:60499ad28ea9 6
JacobBramley 1:ca76237d2965 7 void generate(neopixel::Pixel * out, uint32_t index, uintptr_t extra)
JacobBramley 1:ca76237d2965 8 {
JacobBramley 1:ca76237d2965 9 uint32_t brightness = (index + extra) >> 3;
JacobBramley 1:ca76237d2965 10 out->red = ((index + extra) & 0x1) ? brightness : 0;
JacobBramley 1:ca76237d2965 11 out->green = ((index + extra) & 0x2) ? brightness : 0;
JacobBramley 1:ca76237d2965 12 out->blue = ((index + extra) & 0x4) ? brightness : 0;
JacobBramley 0:60499ad28ea9 13 }
JacobBramley 0:60499ad28ea9 14
JacobBramley 1:ca76237d2965 15 int main()
JacobBramley 1:ca76237d2965 16 {
JacobBramley 1:ca76237d2965 17 // Create a temporary DigitalIn so we can configure the pull-down resistor.
JacobBramley 1:ca76237d2965 18 // (The mbed API doesn't provide any other way to do this.)
JacobBramley 1:ca76237d2965 19 // An alternative is to connect an external pull-down resistor.
JacobBramley 1:ca76237d2965 20 DigitalIn(DATA_PIN, PullDown);
JacobBramley 1:ca76237d2965 21
JacobBramley 1:ca76237d2965 22 // The pixel array control class.
JacobBramley 1:ca76237d2965 23 neopixel::PixelArray array(DATA_PIN);
JacobBramley 1:ca76237d2965 24
JacobBramley 1:ca76237d2965 25 uint32_t offset = 0;
JacobBramley 1:ca76237d2965 26 while (1) {
JacobBramley 1:ca76237d2965 27 array.update(generate, 100, offset++);
JacobBramley 1:ca76237d2965 28 wait_ms(250);
JacobBramley 0:60499ad28ea9 29 }
JacobBramley 0:60499ad28ea9 30 }