cy liang
/
blip_rainbow_mbed-os
blip_rainbow for Mbed OS 5.x
main.cpp@0:60499ad28ea9, 2014-07-25 (annotated)
- Committer:
- JacobBramley
- Date:
- Fri Jul 25 15:22:59 2014 +0000
- Revision:
- 0:60499ad28ea9
- Child:
- 1:ca76237d2965
Demo for the neopixel-spi library. This is untested because I don't yet have any NeoPixels to test it with.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JacobBramley | 0:60499ad28ea9 | 1 | #include "mbed.h" |
JacobBramley | 0:60499ad28ea9 | 2 | #include "neopixel-spi.h" |
JacobBramley | 0:60499ad28ea9 | 3 | |
JacobBramley | 0:60499ad28ea9 | 4 | // A backing store for the pixel data. |
JacobBramley | 0:60499ad28ea9 | 5 | static size_t const count = 16; |
JacobBramley | 0:60499ad28ea9 | 6 | neopixel::Pixel pixels[count]; |
JacobBramley | 0:60499ad28ea9 | 7 | |
JacobBramley | 0:60499ad28ea9 | 8 | // The pixel array control class. |
JacobBramley | 0:60499ad28ea9 | 9 | neopixel::Array array(p30); |
JacobBramley | 0:60499ad28ea9 | 10 | |
JacobBramley | 0:60499ad28ea9 | 11 | uint8_t IntensityForIndex(size_t index) { |
JacobBramley | 0:60499ad28ea9 | 12 | uint32_t c = index % 512; |
JacobBramley | 0:60499ad28ea9 | 13 | return (c >= 256) ? (256 - c) : c; |
JacobBramley | 0:60499ad28ea9 | 14 | } |
JacobBramley | 0:60499ad28ea9 | 15 | |
JacobBramley | 0:60499ad28ea9 | 16 | int main() { |
JacobBramley | 0:60499ad28ea9 | 17 | size_t offset = 0; |
JacobBramley | 0:60499ad28ea9 | 18 | while (1) { |
JacobBramley | 0:60499ad28ea9 | 19 | for (size_t i = 0; i < count; i++) { |
JacobBramley | 0:60499ad28ea9 | 20 | pixels[i].red = IntensityForIndex((i * 10) + offset); |
JacobBramley | 0:60499ad28ea9 | 21 | pixels[i].green = IntensityForIndex((i * 20) + offset); |
JacobBramley | 0:60499ad28ea9 | 22 | pixels[i].blue = IntensityForIndex((i * 40) + offset); |
JacobBramley | 0:60499ad28ea9 | 23 | } |
JacobBramley | 0:60499ad28ea9 | 24 | array.Update(pixels, count); |
JacobBramley | 0:60499ad28ea9 | 25 | wait_ms(10); |
JacobBramley | 0:60499ad28ea9 | 26 | offset++; |
JacobBramley | 0:60499ad28ea9 | 27 | } |
JacobBramley | 0:60499ad28ea9 | 28 | } |