Skip to content

Commit f1083b1

Browse files
authored
Merge pull request #13 from brimshot/timing-fixes
performance
2 parents d864a6a + ed9ca7a commit f1083b1

5 files changed

Lines changed: 31 additions & 65 deletions

File tree

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,7 @@ void setup() {
6363
6464
// ~ Configure quickPatterns
6565
66-
// Due to a potential latching issue when writing data, we use a hard delay for timing with the ESP8266
67-
#ifdef ESP8266
68-
quickPatterns.setTickMillis(0);
69-
#endif
70-
71-
#ifndef ESP8266
7266
quickPatterns.setTickMillis(TICKLENGTH);
73-
#endif
7467
7568
//cylon of 8 pixels that cycles through the rainbow
7669
quickPatterns.addPattern(new qpBouncingBars(8))
@@ -86,12 +79,9 @@ void setup() {
8679
8780
void loop()
8881
{
89-
quickPatterns.draw();
90-
FastLED.show();
91-
92-
#ifdef ESP8266
93-
FastLED.delay(TICKLENGTH);
94-
#endif
82+
// Refresh lights only when new frame data available, prevents issues with data timing on fast processors
83+
if(quickPatterns.draw())
84+
FastLED.show();
9585
}
9686
```
9787

@@ -130,12 +120,14 @@ void setup() {
130120
}
131121
```
132122

133-
Finally, in your *loop()* function, call the *draw()* method of the quickPatterns controller and then FastLED.show()
123+
Finally, in your *loop()* function, call the *draw()* method of the quickPatterns controller and then FastLED.show() when new frame data is available (*draw()* returns true).
124+
134125
```
135126
void loop()
136127
{
137-
quickPatterns.draw();
138-
FastLED.show();
128+
// Refresh lights only when new frame data available, prevents issues with data timing on fast processors
129+
if(quickPatterns.draw())
130+
FastLED.show();
139131
}
140132
```
141133

@@ -765,4 +757,4 @@ Section of lights of length *size* that move back and forth randomly along the l
765757
---
766758
Copyright (c) 2020 Chris Brim
767759

768-
Tested platforms: ESP8266, ESP32, Teensy 3.2, Arduino Mega
760+
Tested platforms: ESP8266, ESP32, Teensy 3.2, Teensy 4.0, Arduino Mega

examples/bulb_lights/bulb_lights.ino

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ SOFTWARE.
3232
#include <quickPatterns.h>
3333

3434
#define CHIPSET WS2811
35-
#define PIN_A 8
35+
#define DATA_PIN 8
3636
#define NUM_LEDS 100
3737
#define BRIGHTNESS 32
3838
#define COLOR_ORDER RGB //GRB for WS2812, RGB for WS2811
39-
#define TICKLENGTH 20
39+
#define TICKLENGTH 25
4040

4141
CRGB leds[NUM_LEDS];
4242

@@ -50,7 +50,7 @@ void setup() {
5050

5151
// ~ Configure FastLED
5252

53-
FastLED.addLeds<CHIPSET, PIN_A, COLOR_ORDER>(leds, NUM_LEDS)
53+
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
5454
.setCorrection(TypicalLEDStrip)
5555
.setDither(BRIGHTNESS < 255);
5656

@@ -63,11 +63,6 @@ void setup() {
6363

6464
quickPatterns.setTickMillis(TICKLENGTH);
6565

66-
// Due to a potential latching issue when writing data, we use a hard delay for timing with the ESP8266
67-
#ifdef ESP8266
68-
quickPatterns.setTickMillis(0);
69-
#endif
70-
7166
// ~
7267

7368
quickPatterns.addPattern(new qpPaletteDissolve(5))
@@ -117,21 +112,15 @@ void setup() {
117112
quickPatterns.sameScene().addPattern(new qpWanderingLine(30))
118113
.singleColor(CRGB::White);
119114
quickPatterns.sameLayer().setLayerBrush(MASK);
120-
121-
122-
123115

124116
}
125117

126118
void loop()
127119
{
128120

129-
quickPatterns.draw();
130-
FastLED.show();
131-
132-
#ifdef ESP8266
133-
FastLED.delay(25);
134-
#endif
121+
// Refresh lights only when new frame data available, prevents issues with data timing on fast processors
122+
if(quickPatterns.draw())
123+
FastLED.show();
135124

136125
EVERY_N_SECONDS(30) {
137126
quickPatterns.nextScene();

examples/flat_strip/flat_strip.ino

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
SOFTWARE.
2626
*****************************************************/
2727

28+
#ifdef CORE_TEENSY
29+
#define FASTLED_ALLOW_INTERRUPTS 0
30+
#endif
31+
2832
#include <quickPatterns.h>
2933

3034
#define CHIPSET WS2812
@@ -48,7 +52,7 @@ void setup() {
4852

4953
// ~ Configure FastLED
5054

51-
FastLED.addLeds<CHIPSET, 8, COLOR_ORDER>(leds, NUM_LEDS)
55+
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
5256
.setCorrection(TypicalLEDStrip)
5357
.setDither(BRIGHTNESS < 255);
5458

@@ -60,15 +64,7 @@ void setup() {
6064

6165
// ~ Configure quickPatterns
6266

63-
// Due to a potential latching issue when writing data, we use a hard delay for timing with the ESP8266
64-
#ifdef ESP8266
65-
quickPatterns.setTickMillis(0);
66-
#endif
67-
68-
#ifndef ESP8266
6967
quickPatterns.setTickMillis(TICKLENGTH);
70-
#endif
71-
7268

7369
// ~ Scene 0 - demonstrates running simultaneous patterns at differing speeds, the same bouncing bars pattern with 3 different configurations will weave in and out of sync
7470

@@ -127,7 +123,7 @@ void setup() {
127123
CRGB *pulseColors = new CRGB[3];
128124
pulseColors[0] = CRGB::Blue;
129125
pulseColors[1] = CRGB::Yellow;
130-
pulseColors[2] = CRGB::Pink;
126+
pulseColors[2] = CRGB::DeepPink;
131127

132128
// small line of pixels that bounces back and forth
133129
quickPatterns.sameScene().addPattern(new qpComet(8))
@@ -174,22 +170,18 @@ void setup() {
174170
quickPatterns.sameLayer().setLayerBrush(MASK).continuallyFadeLayerBy(10);
175171

176172
// small pink runner on top
177-
quickPatterns.sameScene().addPattern(new qpComet(5))
178-
.singleColor(CRGB::HotPink);
173+
quickPatterns.sameScene().addPattern(new qpComet(5, true))
174+
.singleColor(CRGB::DeepPink);
179175

180176
}
181177

182178

183179
void loop()
184180
{
185181

186-
quickPatterns.draw();
187-
FastLED.show();
188-
189-
//On ESP8266 boards due to FastLED latching / write issue, we set our 'tick' length to 0 (see above) and manage the global update speed via hard delay
190-
#ifdef ESP8266
191-
FastLED.delay(TICKLENGTH);
192-
#endif
182+
// Refresh lights only when new frame data available, prevents issues with data timing on fast processors
183+
if(quickPatterns.draw())
184+
FastLED.show();
193185

194186
EVERY_N_SECONDS(30) {
195187
quickPatterns.nextScene();

quickPatterns.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ quickPatterns::quickPatterns(CRGB *leds, int numLeds) {
1212

1313
// Render
1414

15-
void quickPatterns::draw() {
15+
bool quickPatterns::draw() {
1616

1717
uint32_t currentMillis = millis();
1818

@@ -24,18 +24,11 @@ void quickPatterns::draw() {
2424

2525
this->currentScene->draw(this->lightStrand->getLeds(), this->lightStrand->getNumLeds());
2626

27-
//double render will be slooow and also overwrite any fades.....
28-
/*
29-
if(transitioning) {
30-
this->nextScene->draw(this->sceneBuffer, this->numLeds());
31-
if((*transitionFunction)()) {
32-
transitioning = false;
33-
this->currentScene = this->nextScene;
34-
}
35-
}
36-
*/
27+
return true;
3728
}
3829

30+
return false;
31+
3932
}
4033

4134

quickPatterns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class quickPatterns {
5151

5252
// ~ Rendering
5353

54-
void draw();
54+
bool draw();
5555

5656
void setTickMillis(int tickLengthMillis) { this->tickLengthInMillis = tickLengthMillis; }
5757

0 commit comments

Comments
 (0)