Can someone help me figure out how to make the speed of this effect

(Kyle bostick) #1

Can someone help me figure out how to make the speed of this effect adjustable, I attached a link to my code, everything works, but my effect Red White Green Loop is not working the way I would like.

I have several effects, and use my “animation speed” to adjust the speed of the effect without having to change the code, its just a slider i can adjust anytime, the effect i am having issues with will not adjust unless i tweak the “delay” I want to be able to adjust it without editing the sketch.

Lines 707-754 in the Github Link are the effect i am having issues with.
The effects above it have similar code, are are working perfectly. Thanks for taking a look guys

(Marc Miller) #2

Looks like animationspeed is just changing the delay on the overall main loop.

if (animationspeed > 0 && animationspeed < 150) { //Sets animation speed based on receieved value
FastLED.delay(1000 / animationspeed);

If you want it to effect that particular “Red Green White Loop” function you will have to incorporate that variable into that function some how. You could use map, so it varies the delay.

uint8_t delayValue = map ( animationspeed, fromLow, fromHigh, toLow, toHigh );

Also, what happens when the received animationspeed is 150 or greater?

(Kyle bostick) #3

@marmil I am using a system called home assistant, that allows me to use an app to control the LEDs, the maximum animation speed is 150, so i am not sure how i would change it to go beyond 150. There is a slider i can adjust from 0-150 and it determines the speed of the effect. It is just not controlling my newest effect and i am not sure why

I am still pretty new with coding, can you tell me where i would need to insert the functions you are recommending?

(Marc Miller) #4

Try this:
Add this line below line 707:
uint8_t delayValue = map ( animationspeed, 0, 150, 5, 255 );

And then update the four delay(100) lines to:

Adjust the 5 and 255 above to whatever seems like a good minimum and maximum speed. (If you want the max to be more then 255 you will need to change the variable type from unit8_t to unit16_t though.)

Info on the map function here:

(Kyle bostick) #5

@marmil i added the line “uint8_t delayValue = map ( animationspeed, 0, 150, 5, 255 );” on line 708, then i replaced the delay lines with “delay(delayValue);”

i ran the code and tried to use my animation slider to adjust the speed, but it is not working. any other ideas?

(Kyle bostick) #6

One other thing, I am not sure if you could help me with; with this effect when i set it, i have to physically unplug the power supply to change the effect or turn the lights off, its like the D1 stops responding after it starts the “Red White Green Loop” effect

(Marc Miller) #7

Can you edit and update your posted code on github to what it currently is now.
Also, consider deleting all the lines in that function that are commented out or that you are not using in that function (such as the the commented out startIndex related lines). It’s just harder to read with the extra unneeded stuff in there.

And maybe temporarily add a print statement that prints out delayValue so you can confirm if it’s changing (or not).

(Kyle bostick) #8

@marmil I updated the Github, I also removed the commented out lines, I am not sure where to put the print line.

(Marc Miller) #9

@Kyle_bostick Thank you for the update. Here’s my simulated test that seems to be working.

(Marc Miller) #10

I just realized the speed adjustment might seem to interact backward like this:

uint8_t delayValue = map ( animationspeed, 0, 150, 5, 255 );

You can reverse this by flipping one of the pairs like this:

uint8_t delayValue = map ( animationspeed, 0, 150, 255, 5 );