Library to control NeoPixel strings of RGB leds
Dependents: NeoPixelI2cSlave NeoPixelI2cSlave
Effects/shift_effect.cpp@3:7d32f46a38d3, 2016-04-15 (annotated)
- Committer:
- dwini
- Date:
- Fri Apr 15 14:38:13 2016 +0000
- Revision:
- 3:7d32f46a38d3
- Parent:
- 2:bb9ebad05691
Been to long since i coded this.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dwini | 2:bb9ebad05691 | 1 | #include "shift_effect.h" |
dwini | 2:bb9ebad05691 | 2 | #include "colors.h" |
dwini | 2:bb9ebad05691 | 3 | |
dwini | 2:bb9ebad05691 | 4 | namespace Effects { |
dwini | 2:bb9ebad05691 | 5 | |
dwini | 3:7d32f46a38d3 | 6 | ShiftEffect::ShiftEffect(NeoPixelString * pixelstring, neopixel::Pixel color, int delay_ms, int groupsize) |
dwini | 3:7d32f46a38d3 | 7 | : PeriodicEffect(pixelstring, color, delay_ms) { |
dwini | 2:bb9ebad05691 | 8 | |
dwini | 2:bb9ebad05691 | 9 | this->groupsize = groupsize; |
dwini | 2:bb9ebad05691 | 10 | state = FIRST_TIME; |
dwini | 2:bb9ebad05691 | 11 | } |
dwini | 2:bb9ebad05691 | 12 | |
dwini | 2:bb9ebad05691 | 13 | void ShiftEffect::execute(void) { |
dwini | 3:7d32f46a38d3 | 14 | if (shouldExecute()) { |
dwini | 3:7d32f46a38d3 | 15 | clearExecute(); |
dwini | 3:7d32f46a38d3 | 16 | if (state == FIRST_TIME) { |
dwini | 3:7d32f46a38d3 | 17 | for (unsigned i = 0; i < getPixelString()->getLength(); i++) { |
dwini | 3:7d32f46a38d3 | 18 | if (i % groupsize == 0) { |
dwini | 3:7d32f46a38d3 | 19 | getPixelString()->setPixel(i, getColor()); |
dwini | 3:7d32f46a38d3 | 20 | } else { |
dwini | 3:7d32f46a38d3 | 21 | getPixelString()->setPixel(i, Colors::Black); |
dwini | 3:7d32f46a38d3 | 22 | } |
dwini | 2:bb9ebad05691 | 23 | } |
dwini | 2:bb9ebad05691 | 24 | |
dwini | 3:7d32f46a38d3 | 25 | state = RUNNING; |
dwini | 3:7d32f46a38d3 | 26 | } else { |
dwini | 3:7d32f46a38d3 | 27 | |
dwini | 3:7d32f46a38d3 | 28 | unsigned int i = 0; |
dwini | 3:7d32f46a38d3 | 29 | neopixel::Pixel pix; |
dwini | 3:7d32f46a38d3 | 30 | neopixel::Pixel first; |
dwini | 3:7d32f46a38d3 | 31 | |
dwini | 3:7d32f46a38d3 | 32 | while (i < getPixelString()->getLength()) { |
dwini | 3:7d32f46a38d3 | 33 | unsigned int group = i / groupsize; |
dwini | 3:7d32f46a38d3 | 34 | |
dwini | 3:7d32f46a38d3 | 35 | if (i % groupsize == 0) { |
dwini | 3:7d32f46a38d3 | 36 | first = getPixelString()->getPixel(i); |
dwini | 3:7d32f46a38d3 | 37 | } |
dwini | 3:7d32f46a38d3 | 38 | |
dwini | 3:7d32f46a38d3 | 39 | if (i == ((group+1)*groupsize)-1) { // last pix in group |
dwini | 3:7d32f46a38d3 | 40 | getPixelString()->setPixel(i, first); |
dwini | 3:7d32f46a38d3 | 41 | } else { |
dwini | 3:7d32f46a38d3 | 42 | pix = getPixelString()->getPixel(i+1); |
dwini | 3:7d32f46a38d3 | 43 | getPixelString()->setPixel(i, pix); |
dwini | 3:7d32f46a38d3 | 44 | } |
dwini | 3:7d32f46a38d3 | 45 | |
dwini | 3:7d32f46a38d3 | 46 | i++; |
dwini | 2:bb9ebad05691 | 47 | } |
dwini | 2:bb9ebad05691 | 48 | |
dwini | 2:bb9ebad05691 | 49 | } |
dwini | 3:7d32f46a38d3 | 50 | getPixelString()->update(); |
dwini | 2:bb9ebad05691 | 51 | } |
dwini | 2:bb9ebad05691 | 52 | } |
dwini | 2:bb9ebad05691 | 53 | |
dwini | 2:bb9ebad05691 | 54 | }; |