Skip to content

Commit 066e112

Browse files
committed
fix theaterChase effect
1 parent e74706e commit 066e112

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

examples/strandtest_nodelay/strandtest_nodelay.ino

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ bool patternComplete = false;
4747
int pixelInterval = 50; // Pixel Interval (ms)
4848
int pixelQueue = 0; // Pattern Pixel Queue
4949
int pixelCycle = 0; // Pattern Pixel Cycle
50-
uint16_t pixelCurrent = 0; // Pattern Current Pixel Number
5150
uint16_t pixelNumber = LED_COUNT; // Total Number of Pixels
5251

5352
// setup() function -- runs once at startup --------------------------------
@@ -71,7 +70,6 @@ void loop() {
7170
patternComplete = false;
7271
patternPrevious = currentMillis;
7372
patternCurrent++; // Advance to next pattern
74-
pixelCurrent = 0;
7573
if(patternCurrent >= 7)
7674
patternCurrent = 0;
7775
}
@@ -115,13 +113,12 @@ void loop() {
115113
// strip.Color(red, green, blue) as shown in the loop() function above),
116114
// and a delay time (in milliseconds) between pixels.
117115
void colorWipe(uint32_t color, int wait) {
118-
if(pixelInterval != wait)
119-
pixelInterval = wait; // Update delay time
120-
strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM)
121-
strip.show(); // Update strip to match
122-
pixelCurrent++; // Advance current pixel
123-
if(pixelCurrent >= pixelNumber) { // Loop the pattern from the first LED
124-
pixelCurrent = 0;
116+
static uint16_t current_pixel = 0;
117+
pixelInterval = wait; // Update delay time
118+
strip.setPixelColor(current_pixel++, color); // Set pixel's color (in RAM)
119+
strip.show(); // Update strip to match
120+
if(current_pixel >= pixelNumber) { // Loop the pattern from the first LED
121+
current_pixel = 0;
125122
patternComplete = true;
126123
}
127124
}
@@ -130,18 +127,29 @@ void colorWipe(uint32_t color, int wait) {
130127
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
131128
// between frames.
132129
void theaterChase(uint32_t color, int wait) {
133-
if(pixelInterval != wait)
134-
pixelInterval = wait; // Update delay time
135-
for(int i = 0; i < pixelNumber; i++) {
136-
strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM)
130+
static uint32_t loop_count = 0;
131+
static uint16_t current_pixel = 0;
132+
133+
pixelInterval = wait; // Update delay time
134+
135+
strip.clear();
136+
137+
for(int c=current_pixel; c < pixelNumber; c += 3) {
138+
strip.setPixelColor(c, color);
137139
}
138-
strip.show(); // Update strip to match
139-
for(int i=0; i < pixelNumber; i+=3) {
140-
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM)
140+
strip.show();
141+
142+
current_pixel++;
143+
if (current_pixel >= 3) {
144+
current_pixel = 0;
145+
loop_count++;
146+
}
147+
148+
if (loop_count >= 10) {
149+
current_pixel = 0;
150+
loop_count = 0;
151+
patternComplete = true;
141152
}
142-
pixelQueue++; // Advance current pixel
143-
if(pixelQueue >= 3)
144-
pixelQueue = 0; // Loop the pattern from the first LED
145153
}
146154

147155
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.

0 commit comments

Comments
 (0)