Hey guys! I'm really stuck on this one.

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.

Thanks for your help!

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

What micro controller are you using?

@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???

I’m using a generic “UNO”

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.

Basically you need to make sure that pos+x and pos-x are greater than or equal to 0 and less than NUM_LEDS

@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???

Thanks and glad you guys are back :slight_smile:

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.

[Daniel was 20x+ times faster at solving this then I was. :slight_smile: But I did find that problem also. Yeay.]

@marmil
LOL thanks.
I will try that tomorrow. Got to get up at 4:00 KC time, but thank you all for the help!

@Daniel_Garcia and @marmil

A combination of both of them worked. Thank you very much and have a Blinky Christmas!!!