Un script para cambiar el color
Dependencies: PixelArray USBDevice mbed
Fork of blip_rainbow_ejemplo by
main.cpp@1:ca76237d2965, 2014-08-01 (annotated)
- Committer:
- JacobBramley
- Date:
- Fri Aug 01 22:43:26 2014 +0000
- Revision:
- 1:ca76237d2965
- Parent:
- 0:60499ad28ea9
- Child:
- 3:2d84c8262139
Basic demo application for the PixelArray library.
Who changed what in which revision?
User | Revision | Line number | New 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 | } |