-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMultiBallPlay.cpp
40 lines (33 loc) · 950 Bytes
/
MultiBallPlay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* MultiBallPlay.cpp
*
* Created on: 04.09.2015
* Author: sr
*/
#include "MultiBallPlay.h"
MultiBallPlay::MultiBallPlay(int* index, int num, int animationSpeed) : Effect(0,index,num) {
this->animationDelay = 1000 / animationSpeed;
paletteIndex = 0;
nextUpdate = 0;
SetupBlackAndWhiteStripedPalette();
}
void MultiBallPlay::SetupBlackAndWhiteStripedPalette() {
// 'black out' all 16 palette entries...
fill_solid(pal, 16, CRGB::Black);
// and set every fourth one to white.
pal[0] = CRGB::White;
pal[4] = CRGB::White;
pal[8] = CRGB::White;
pal[12] = CRGB::White;
}
void MultiBallPlay::updateLeds(unsigned long now, CRGB* leds) {
if (active && now > nextUpdate) {
nextUpdate = now + animationDelay;
paletteIndex = paletteIndex + 1; /* motion speed */
int colorIndex = paletteIndex;
for (int i = 0; i < num; i++) {
leds[index[i]] = ColorFromPalette(pal, colorIndex, 255, NOBLEND);
colorIndex += 3;
}
}
}