I've looked through many posts and discussion on this particular topic and have come up lacking.
Code in question:
void theaterChaseRainbow(int cycles, int speed, unsigned long duration){ // TODO direction, duration
duration = 10000L;
unsigned long start = millis();
for (int j=0; j < 256 * cycles; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < NUM_LEDS; i=i+3) {
int pos = i+q;
leds[pos] = Wheel( (i+j) % 255); //turn every third pixel on
}
FastLED.show();
delay(speed);
for (int i=0; i < NUM_LEDS; i=i+3) {
leds[i+q] = CRGB::Black; //turn every third pixel off
}
}
unsigned long current = millis();
unsigned long delta = current-start;
if(delta > duration) {
return;
}
}
}
No matter what I do the millis seems to be clocking wait to fast, i.e. I set the delay to 10000ms and it is done in a something like 1000ms
If I chose to print out millis(), i.e. I add the line
mySerial.println(millis())
everything slows down nicely.
if I do something like:
mySerial.println(delta);
I get a single rather oddly long value something like 4294963562
Why is millis behaving like this? Enquiring minds want to know.
Yeah that shouldn’t happen. This sounds awfully like something is wrong elsewhere.
Are you sure you aren’t overrunning your LED array?
So we need to see all the code OR a small example you have created from your code, a complete program that compiles, runs and exhibits the same undesirable behaviour.
Also, fastLED will have an impact on millis() timing. Probably not an issue, but you should google it to see how they get along.
If NUM_LEDS is not a multiple of 3, your code will write outside of the leds array, this is called buffer overflow and will cause all sorts of strange behaviors or even crash your program. Always make sure an array index is never greater than the array size - 1.
That is an interesting note for sure, I hadn't considered that, it definitly isn't a multiple of 3, I could be banging into other parts of memory that are causing issues.
If you have assignments to you led array all over the place, you could replace them all with a function call, a function which takes pixel number and color as arguments.
Isolating to one place where you could do all the bounds checking you need.
Either ignore or complain about attempts to write outside your array that come through this one function.
You are getting a lot of random guesses because you have only shared a snippet of your code. You need to write a complete working example of your code that presents the problem. It is not millis(), it is not delay(unsigned long) and it is not writing to memory past your array. You can remark out the for(int i=0) loop to check that... but, you pass 3 parameters to the function, which are unknown to us on the forum. You reference additional globals, including the array, and class member functions that are not presented to the forum. It was said before, and I just said it, but you need to present more code, and you can simplify your code the the example as well.