Skip to content

Commit 29f1020

Browse files
improved plasma demo for long term operations
1 parent 653020c commit 29f1020

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

examples/plasma-10x10/plasma-10x10.ino

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,34 @@ void setup() {
8585

8686
unsigned long loopCounter = 0;
8787
unsigned long timeCount = 0;
88+
bool timeIncrement = true;
8889

89-
const unsigned long loopMod = 500;
90+
const unsigned long loopMod = 50;
9091

9192
void loop() {
9293
leds.loop();
9394
loopCounter++;
9495

9596
if (loopCounter == loopMod) {
96-
timeCount++;
97+
if (timeIncrement) {
98+
timeCount++;
99+
100+
//
101+
// set a maximum to timeCount because floats only have
102+
// a max precision of 5 significant digits. Otherwise, when timeCount
103+
// gets too large, the animation will get choppy because calls to drawPlasma()
104+
// will not have a noticable change to timeCount/TIME_DILATION. for several
105+
// consecutive calls.
106+
//
107+
if (timeCount >= 1000*PI) {
108+
timeIncrement = false;
109+
}
110+
} else {
111+
timeCount--;
112+
if (timeCount == 0) {
113+
timeIncrement = true;
114+
}
115+
}
97116
drawPlasma(timeCount);
98117
loopCounter = 0;
99118
}

examples/plasma-8x8/plasma-8x8.ino

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void setup() {
8585

8686
unsigned long loopCounter = 0;
8787
unsigned long timeCount = 0;
88+
bool timeIncrement = true;
8889

8990
const unsigned long loopMod = 500;
9091

@@ -93,7 +94,25 @@ void loop() {
9394
loopCounter++;
9495

9596
if (loopCounter == loopMod) {
96-
timeCount++;
97+
if (timeIncrement) {
98+
timeCount++;
99+
100+
//
101+
// set a maximum to timeCount because floats only have
102+
// a max precision of 5 significant digits. Otherwise, when timeCount
103+
// gets too large, the animation will get choppy because calls to drawPlasma()
104+
// will not have a noticable change to timeCount/TIME_DILATION. for several
105+
// consecutive calls.
106+
//
107+
if (timeCount >= 100000*PI) {
108+
timeIncrement = false;
109+
}
110+
} else {
111+
timeCount--;
112+
if (timeCount == 0) {
113+
timeIncrement = true;
114+
}
115+
}
97116
drawPlasma(timeCount);
98117
loopCounter = 0;
99118
}

0 commit comments

Comments
 (0)