|
@@ -1,21 +1,28 @@
|
1
|
1
|
#include "aura.h"
|
|
2
|
+#include "color.h"
|
2
|
3
|
|
3
|
4
|
// ==== The Aura Rainbow Effect ====
|
4
|
|
-// TODO: Implement arbitrary color selection
|
5
|
5
|
int auraCounter = 0;
|
6
|
|
-int auraWidth = NUM_LEDS / 3;
|
7
|
|
-int auraDecrement;
|
|
6
|
+int auraWidth;
|
|
7
|
+unsigned char paletteCounter;
|
|
8
|
+CRGB curColor, nextColor;
|
8
|
9
|
|
9
|
10
|
void AuraEffect::reset() {
|
10
|
11
|
auraCounter = 0;
|
|
12
|
+ paletteCounter = 0;
|
11
|
13
|
auraWidth = NUM_LEDS / 3;
|
12
|
|
- auraDecrement = MAX_BRIGHTNESS / auraWidth;
|
13
|
14
|
}
|
14
|
15
|
|
15
|
|
-void AuraEffect::onUpdate() {
|
16
|
|
- auraCounter = (auraCounter + 1) % (auraWidth * 3); // 3 = R G B
|
17
|
|
- int cycleProgress = auraDecrement * (auraCounter % auraWidth);
|
|
16
|
+void AuraEffect::stepColor() {
|
|
17
|
+ curColor = *getPaletteColor(paletteCounter);
|
|
18
|
+ nextColor = *nextPaletteColor(&paletteCounter);
|
|
19
|
+}
|
|
20
|
+
|
|
21
|
+void AuraEffect::postInit() {
|
|
22
|
+ this->stepColor();
|
|
23
|
+}
|
18
|
24
|
|
|
25
|
+void AuraEffect::onUpdate() {
|
19
|
26
|
// Shift all LEDs left by 1 px
|
20
|
27
|
for (int i = 0; i < NUM_LEDS - 1; i++) {
|
21
|
28
|
leds[i] = CRGB(leds[i + 1].r, leds[i + 1].g, leds[i + 1].b);
|
|
@@ -23,14 +30,12 @@ void AuraEffect::onUpdate() {
|
23
|
30
|
|
24
|
31
|
// Calculate the color for the last LED
|
25
|
32
|
int last = NUM_LEDS - 1;
|
26
|
|
- if (auraCounter < auraWidth) {
|
27
|
|
- // RED
|
28
|
|
- leds[last] = CRGB(MAX_BRIGHTNESS - cycleProgress, cycleProgress, 0);
|
29
|
|
- } else if (auraCounter < auraWidth * 2) {
|
30
|
|
- // GREEN
|
31
|
|
- leds[last] = CRGB(0, MAX_BRIGHTNESS - cycleProgress, cycleProgress);
|
32
|
|
- } else {
|
33
|
|
- // BLUE
|
34
|
|
- leds[last] = CRGB(cycleProgress, 0, MAX_BRIGHTNESS - cycleProgress);
|
|
33
|
+ leds[last] = blendColor(curColor, nextColor, auraCounter, auraWidth);
|
|
34
|
+
|
|
35
|
+ if (auraCounter == (auraWidth - 1)) {
|
|
36
|
+ this->stepColor();
|
35
|
37
|
}
|
|
38
|
+
|
|
39
|
+ // Increment the counter
|
|
40
|
+ auraCounter = (auraCounter + 1) % auraWidth;
|
36
|
41
|
}
|