Jacob Bramley
/
NeoPixel Demo
Demo application for Adafruit NeoPixels.
main.cpp
- Committer:
- JacobBramley
- Date:
- 2015-03-12
- Revision:
- 2:b70964f8a427
- Parent:
- 1:ca76237d2965
File content as of revision 2:b70964f8a427:
#include "mbed.h" #include "neopixel.h" // This must be an SPI MOSI pin. #define DATA_PIN p5 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() { // 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); } }