Library to control NeoPixel strings of RGB leds
Dependents: NeoPixelI2cSlave NeoPixelI2cSlave
Diff: Effects/shift_effect.cpp
- Revision:
- 2:bb9ebad05691
- Child:
- 3:7d32f46a38d3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Effects/shift_effect.cpp Mon Nov 23 21:32:24 2015 +0000 @@ -0,0 +1,54 @@ +#include "shift_effect.h" +#include "colors.h" + +namespace Effects { + + ShiftEffect::ShiftEffect(NeoPixelString * pixelstring, int delay_ms, neopixel::Pixel color, int groupsize) + : Effect(pixelstring, delay_ms) { + + this->color = color; + this->groupsize = groupsize; + state = FIRST_TIME; + } + + void ShiftEffect::execute(void) { + Effect::execute(); + + if (state == FIRST_TIME) { + for (unsigned i = 0; i < getPixelString()->getLength(); i++) { + if (i % groupsize == 0) { + getPixelString()->setPixel(i, color); + } else { + getPixelString()->setPixel(i, Colors::Black); + } + } + + state = RUNNING; + } else { + + unsigned int i = 0; + neopixel::Pixel pix; + neopixel::Pixel first; + + while (i < getPixelString()->getLength()) { + unsigned int group = i / groupsize; + + if (i % groupsize == 0) { + first = getPixelString()->getPixel(i); + } + + if (i == ((group+1)*groupsize)-1) { // last pix in group + getPixelString()->setPixel(i, first); + } else { + pix = getPixelString()->getPixel(i+1); + getPixelString()->setPixel(i, pix); + } + + i++; + } + + } + getPixelString()->update(); + } + +}; \ No newline at end of file