I have a custom colorWipe
function that I've built to be non-blocking so that I can turn the sequence off in the middle of a sequence.
//util globals
#include <Util.h>
#define LIGHT_PIN 7
#define LIGHT_DELAY 15
DataTONF lightPinTONF;
//LED globals
#include <FastLED.h>
#define LED_PIN 3
//#define NUM_LEDS 27 //dev
#define NUM_LEDS 384 //production
#define BRIGHTNESS 180 // scale 0-255
CRGB LEDs[NUM_LEDS];
unsigned long seqStartTime = 0;
unsigned long seqTimeNow = 0;
bool seqDone = false;
unsigned long seqCount = 0;
void setup()
{
//utils setup
pinMode(LIGHT_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
lightPinTONF.pin = LIGHT_PIN;
lightPinTONF.PRE = LIGHT_DELAY;
lightPinTONF.DN = false;
//LED setup
FastLED.addLeds<WS2811, LED_PIN>(LEDs, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.show();
pinMode(LIGHT_PIN, INPUT);
delay(3000);
seqStartTime = millis();
}
void loop()
{
digitalReadTONF(lightPinTONF);
bool isNightTime = lightPinTONF.DN;
digitalWrite(LED_BUILTIN, isNightTime);
if (isNightTime)
{
if (seqDone)
{
seqStartTime = millis();
seqTimeNow = seqStartTime;
seqDone = false;
seqCount++;
}
else
{
seqTimeNow = millis();
}
unsigned long color = 0x0;
switch(seqCount % 3)
{
case 0:
color = 0xFF0000;
break;
case 1:
color = 0x00FF00;
break;
case 2:
color = 0x0000FF;
break;
}
int timeElapsed = 0;
if (seqTimeNow >= seqStartTime)
{
timeElapsed = seqTimeNow - seqStartTime;
}
else
{
timeElapsed = (4294967295 - seqStartTime) + seqTimeNow + 1;
}
seqDone = colorWipe(timeElapsed, 120, color);
}
else
{
seqDone = true;
seqCount = -1;
FastLED.clear();
FastLED.show();
}
}
bool colorWipe(int timeElapsed, int interval, unsigned long hexColor)
{
int intervalInt = static_cast<int>(interval);
LEDs[timeElapsed / intervalInt] = hexColor;
FastLED.show();
if ((timeElapsed / intervalInt) >= (NUM_LEDS - 1))
{
return true;
}
return false;
}
Everything seems to work perfectly when I use my 27 pixel test strip. However, if I change the number of LEDs to 384, the first color will wipe onto the strip, but the second color wipe never starts. Seems like it gets hung up somewhere. The sequence is still physically running on the 27 pixel test strip, but it should just overrun to "virtual" pixels and cycle back around.
What's weird is I've tried many different combinations of intervals for the colorWipe
with the number of LEDs and some work, some don't. For instance, if I use 80 ms interval, instead of 120 ms and 384 pixels, it works just fine. 150 pixels with 120 ms interval, again it works just fine.
Util.cpp (2.4 KB)
Util.h (561 Bytes)
I can't figure out why it won't work with 384 pixels and 120 ms intervals.