A program that fades between a selection of colors.
Dependencies: PixelArray WS2812 mbed
main.cpp@0:de636c7cdfda, 2017-03-12 (annotated)
- Committer:
- theros
- Date:
- Sun Mar 12 14:56:52 2017 +0000
- Revision:
- 0:de636c7cdfda
- Child:
- 1:ad5c2cfb2002
First Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
theros | 0:de636c7cdfda | 1 | #include "mbed.h" |
theros | 0:de636c7cdfda | 2 | #include "WS2812.h" |
theros | 0:de636c7cdfda | 3 | #include "PixelArray.h" |
theros | 0:de636c7cdfda | 4 | |
theros | 0:de636c7cdfda | 5 | #define WS2812_BUF 77 //number of LEDs in the array |
theros | 0:de636c7cdfda | 6 | #define NUM_COLORS 6 //number of colors to store in the array |
theros | 0:de636c7cdfda | 7 | |
theros | 0:de636c7cdfda | 8 | DigitalIn usrBtn(USER_BUTTON); |
theros | 0:de636c7cdfda | 9 | DigitalOut usrLed(LED1); |
theros | 0:de636c7cdfda | 10 | PixelArray px(WS2812_BUF); |
theros | 0:de636c7cdfda | 11 | |
theros | 0:de636c7cdfda | 12 | // See the program page for information on the timing numbers |
theros | 0:de636c7cdfda | 13 | WS2812 ws(D9, WS2812_BUF, 6,17,9,14); //nucleo-f411re |
theros | 0:de636c7cdfda | 14 | |
theros | 0:de636c7cdfda | 15 | int main() |
theros | 0:de636c7cdfda | 16 | { |
theros | 0:de636c7cdfda | 17 | int colorIdx = 0; |
theros | 0:de636c7cdfda | 18 | |
theros | 0:de636c7cdfda | 19 | ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling |
theros | 0:de636c7cdfda | 20 | |
theros | 0:de636c7cdfda | 21 | // set up the colours we want to draw with |
theros | 0:de636c7cdfda | 22 | int colorbuf[NUM_COLORS] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f}; |
theros | 0:de636c7cdfda | 23 | |
theros | 0:de636c7cdfda | 24 | // Now the buffer is written, write it to the led array. |
theros | 0:de636c7cdfda | 25 | while (1) |
theros | 0:de636c7cdfda | 26 | { |
theros | 0:de636c7cdfda | 27 | //write the color value for each pixel |
theros | 0:de636c7cdfda | 28 | px.SetAll(colorbuf[colorIdx]); |
theros | 0:de636c7cdfda | 29 | |
theros | 0:de636c7cdfda | 30 | //write the II value for each pixel |
theros | 0:de636c7cdfda | 31 | px.SetAllI(64); |
theros | 0:de636c7cdfda | 32 | |
theros | 0:de636c7cdfda | 33 | for (int i = WS2812_BUF; i >= 0; i--) |
theros | 0:de636c7cdfda | 34 | { |
theros | 0:de636c7cdfda | 35 | ws.write(px.getBuf()); |
theros | 0:de636c7cdfda | 36 | } |
theros | 0:de636c7cdfda | 37 | |
theros | 0:de636c7cdfda | 38 | colorIdx++; |
theros | 0:de636c7cdfda | 39 | |
theros | 0:de636c7cdfda | 40 | if (colorIdx >= NUM_COLORS) |
theros | 0:de636c7cdfda | 41 | { |
theros | 0:de636c7cdfda | 42 | colorIdx = 0; |
theros | 0:de636c7cdfda | 43 | } |
theros | 0:de636c7cdfda | 44 | } |
theros | 0:de636c7cdfda | 45 | } |