A program that fades between a selection of colors.
Dependencies: PixelArray WS2812 mbed
Diff: main.cpp
- Revision:
- 2:381421ec57e1
- Parent:
- 1:ad5c2cfb2002
- Child:
- 3:b99f66d3e77e
--- a/main.cpp Sun Mar 12 16:51:05 2017 +0000 +++ b/main.cpp Sun Mar 12 22:23:08 2017 +0000 @@ -4,7 +4,7 @@ #define WS2812_BUF 77 //number of LEDs in the array #define NUM_COLORS 6 //number of colors to store in the array -#define NUM_STEPS 32 //number of steps between colors +#define NUM_STEPS 8 //number of steps between colors DigitalIn usrBtn(USER_BUTTON); DigitalOut usrLed(LED1); @@ -42,15 +42,6 @@ // Now the buffer is written, write it to the led array. while (1) { - if ((colorIdx + 1) > NUM_COLORS) - { - colorTo = 0; - } - else - { - colorTo = (colorIdx + 1); - } - //get starting RGB components for interpolation std::size_t c1 = colorbuf[colorFrom]; std::size_t r1 = (c1 & 0xff0000) >> 16; @@ -85,6 +76,7 @@ } } + colorFrom = colorIdx; colorIdx++; if (colorIdx >= NUM_COLORS) @@ -92,6 +84,6 @@ colorIdx = 0; } - colorFrom = colorIdx; + colorTo = colorIdx; } }