Demo of NeoPixels using buffer/array of pixels method.
Dependencies: PixelArrayBuffer mbed
Edit of Jacob Bramley's original NeoPixel Demo code. https://developer.mbed.org/users/JacobBramley/code/NeoPixel-Demo/ This code simply demos the buffer/array of pixels method in updating the NeoPixel chain. The original version of this code used the generator method.
main.cpp@0:69bfb2320a83, 2015-03-10 (annotated)
- Committer:
- ben_ceron
- Date:
- Tue Mar 10 06:26:24 2015 +0000
- Revision:
- 0:69bfb2320a83
Buffer method demo.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ben_ceron | 0:69bfb2320a83 | 1 | #include "mbed.h" |
ben_ceron | 0:69bfb2320a83 | 2 | #include "neopixel.h" |
ben_ceron | 0:69bfb2320a83 | 3 | |
ben_ceron | 0:69bfb2320a83 | 4 | // This must be an SPI MOSI pin. |
ben_ceron | 0:69bfb2320a83 | 5 | #define DATA_PIN p5 |
ben_ceron | 0:69bfb2320a83 | 6 | |
ben_ceron | 0:69bfb2320a83 | 7 | |
ben_ceron | 0:69bfb2320a83 | 8 | int main() |
ben_ceron | 0:69bfb2320a83 | 9 | { |
ben_ceron | 0:69bfb2320a83 | 10 | |
ben_ceron | 0:69bfb2320a83 | 11 | |
ben_ceron | 0:69bfb2320a83 | 12 | // Create a temporary DigitalIn so we can configure the pull-down resistor. |
ben_ceron | 0:69bfb2320a83 | 13 | // (The mbed API doesn't provide any other way to do this.) |
ben_ceron | 0:69bfb2320a83 | 14 | // An alternative is to connect an external pull-down resistor. |
ben_ceron | 0:69bfb2320a83 | 15 | DigitalIn(DATA_PIN, PullDown); |
ben_ceron | 0:69bfb2320a83 | 16 | |
ben_ceron | 0:69bfb2320a83 | 17 | // The pixel array control class. |
ben_ceron | 0:69bfb2320a83 | 18 | neopixel::PixelArray array(DATA_PIN); |
ben_ceron | 0:69bfb2320a83 | 19 | // Declare array/buffer of type Pixel. |
ben_ceron | 0:69bfb2320a83 | 20 | uint16_t numPixels = 4; |
ben_ceron | 0:69bfb2320a83 | 21 | neopixel::Pixel pixels[numPixels]; |
ben_ceron | 0:69bfb2320a83 | 22 | // Use buffer method of updating pixels. |
ben_ceron | 0:69bfb2320a83 | 23 | pixels[0].red = 255; |
ben_ceron | 0:69bfb2320a83 | 24 | pixels[0].green = 0; |
ben_ceron | 0:69bfb2320a83 | 25 | pixels[0].blue = 0; |
ben_ceron | 0:69bfb2320a83 | 26 | pixels[1].red = 255; |
ben_ceron | 0:69bfb2320a83 | 27 | pixels[1].green = 140; |
ben_ceron | 0:69bfb2320a83 | 28 | pixels[1].blue = 0; |
ben_ceron | 0:69bfb2320a83 | 29 | pixels[2].red = 0; |
ben_ceron | 0:69bfb2320a83 | 30 | pixels[2].green = 255; |
ben_ceron | 0:69bfb2320a83 | 31 | pixels[2].blue = 0; |
ben_ceron | 0:69bfb2320a83 | 32 | pixels[3].red = 0; |
ben_ceron | 0:69bfb2320a83 | 33 | pixels[3].green = 0; |
ben_ceron | 0:69bfb2320a83 | 34 | pixels[3].blue = 255; |
ben_ceron | 0:69bfb2320a83 | 35 | while (1) { |
ben_ceron | 0:69bfb2320a83 | 36 | array.update(pixels, numPixels); |
ben_ceron | 0:69bfb2320a83 | 37 | |
ben_ceron | 0:69bfb2320a83 | 38 | } |
ben_ceron | 0:69bfb2320a83 | 39 | } |