Library to control NeoPixel strings of RGB leds
Dependents: NeoPixelI2cSlave NeoPixelI2cSlave
Effects/shift_effect.cpp
- Committer:
- dwini
- Date:
- 2015-11-23
- Revision:
- 2:bb9ebad05691
- Child:
- 3:7d32f46a38d3
File content as of revision 2:bb9ebad05691:
#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(); } };