-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LED strip library: fading #74
Comments
Perhaps consider the modulo operator ... ? |
If I understand this correctly, your rate variable is just being added/subtracted each time loop is called? How about this? if(goingUp[i])
{
if(ledPos[i].r + fadeRate > 255)
{
goingUp[i] = false;
// Set your leds to the maximum brightness here if you like
}
else {
ledPos[i].r += fadeRate;
ledPos[i].g += fadeRate;
ledPos[i].b += fadeRate;
}
}
else
{
// Do a similar operation but with -fadeRate
}
... |
The modulo still messes with my brain, so I went with Mike's suggestion. Works like a charm, thanks! |
nice. ... but ... you will not regret mastering the modulus! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there,
I have a problem making my LEDs fade individually. The problem is that the library that controls the strip only allows brightness values for RBG 0-255, and if it goes over that, it will loop back to 0.
This means that the following code never gets into the second if-loop to have goingUp become
false
.Now I could set it to
>250
. However, iffadeRate = 20
it would go from240
back to0
before reachinggoingUp[i] = false
, because the library doesn't allow it to go over 255. Is there a smart way to go around that while still being able to have a variablefadeRate
?Thanks,
Tobias
The text was updated successfully, but these errors were encountered: