-
Notifications
You must be signed in to change notification settings - Fork 4
/
Motion.cpp
51 lines (43 loc) · 1.32 KB
/
Motion.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
41
42
43
44
45
46
47
48
49
50
51
#include "Motion.h"
Motion::Motion(Strip *strip, AudioChannel *audioChannel, State *state, CRGB color, double velocityFactor, double accelerationFactor) : Fx(strip, audioChannel, state) {
this->color = color;
this->velocityFactor = velocityFactor;
this->accelerationFactor = accelerationFactor;
audioTrigger = new AudioTrigger(audioChannel);
for (uint8_t i = 0; i < ITEMS; i++) {
items[i].ball.setup(strip);
}
}
Motion::~Motion() {
delete audioTrigger;
}
void Motion::reset() {
clear();
for (int i = 0; i < ITEMS; i++) {
items[i].ball.reset();
}
fadeTimer.reset();
inhibitTimer.reset();
}
void Motion::loop() {
if (fadeTimer.isElapsed()) {
strip->fade(FADE_RATE);
}
bool trigger = audioTrigger->triggered(3);
if (trigger && items[nextItem].ball.isStable() && inhibitTimer.isElapsed()) {
inhibitTimer.reset();
resetItem(items[nextItem]);
nextItem = (nextItem + 1) % ITEMS;
}
for (uint8_t i = 0; i < ITEMS; i++) {
items[i].ball.loop();
}
}
void Motion::resetItem(Item &item) {
item.ball.reset()
.setColor(color)
.setVelocity(velocityFactor * state->linearFxSpeed)
.setAcceleration(accelerationFactor * state->linearFxSpeed)
.setPosition(0)
.setUpperBound(strip->last());
}