Hey guys!
I’m really stuck on this one.
Line 51 outputs “12” and that’s it, when it should be like “127”. The backward() function does nothing. If I change the Serial.print to NUM_LEDS, it says 112 and only goes thru the loop once. Next time it loops thru it says 12.
I didn’t dig into it, but my very first thought was does it have anything to do with int8_t vs uint8_t?
int8_t pos //Has value range of -128 to 127
uint8_t pos //Has a value range of 0 to 255
@marmil
Unfortunately that made no difference, but does make sense tho. Funny thing is the “forward” part of the loop works just fine, it’s just the “backwards” does nothing.
If I Serial.print the “NUM_LEDS” in line 51 it gives me “112”, but it’s #defined as 132. but when it loops back to the “forward” part of the function, everything works just fine???
In backwards, pos starts out with a value of 127 - but the you have a loop where you are setting leds[pos +x] when x is 13 and 127 + 13 is 140 - which is outside of your leds array which means you’re writing into random memory - which will cause all sorts of weird stuff to happen.
@Daniel_Garcia
Thank you, I didn’t catch that. But look where the print function is, it’s before the math function.
I’m not a real good coder, and I’m having trouble making it change directions smoothly.
Even if I took out the “NUM_LEDS-5” and replaced it with “127” it still did nothing .
And BTW I had a delay at line 65 to slow things down and nothing showed on the strip(WS2812B’s), I just removed it to clean up the code before I posted it.
I’ll change the overflow part of the math function. Good eye, thanks, just can’t figure out why the NUM_LEDS can change???
Line 61 is your problem as that adds up to a value above NUM_LEDS which causes problems.
Try changing it from:
leds[pos + x] = CHSV(gHue, 255, fade );
To
leds[ (pos + x) % NUM_LEDS ] = CHSV(gHue, 255, fade );
Or rework something so it doesn’t ever go above your NUM_LEDS value.