Skip to content
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

How to change fade_speed on the fly? #3

Open
Rimbaldo opened this issue Jul 21, 2024 · 3 comments
Open

How to change fade_speed on the fly? #3

Rimbaldo opened this issue Jul 21, 2024 · 3 comments

Comments

@Rimbaldo
Copy link

Rimbaldo commented Jul 21, 2024

Hi! When using fadinglight, I need to change on the fly the time in ms that fade_speed changes, when using patterns. For instance, If I want to use a pattern blink that takes 2 seconds to be fully on and 2 seconds to be fully off, I need to decrease fade_speed to 2ms. But if I'll use 200 ms to be fully on and then 200 ms to be fully OFF, 30ms as fade_speed works better. So how can I, in the same code change the fade_speed?

Could Fade_speed be put as a parameter inside that speed Setting struct, that allows us to change the pattern blink settings on the fly?

Thanks a lot for your library!

Best Regards, Rodrigo

@Rimbaldo
Copy link
Author

Well, I found out an easy solution. I just created another function inside basefader.h:

void setFadeSpeed(int fspeed) { fadeSpeed_ = fspeed; }

and it worked. I just need to call LEDX.setFadeSpeed(value desired) and it changes accordingly. It seems to work so far... But you could check it out if nothing else breaks...

On a side note, not related to this, when I use logarithmic mode to fade a led the result is horrible, it blinks weirdly. If I use log OFF then the LED smoothly fades in and out, with no weird blinking... at least on an Attiny85 and 167, which are the ones I'm using.. So I'm sticking to non-log fading so far..

Best Regards, Rodrigo

@tfeldmann
Copy link
Owner

Good solution, thats what I was about to recommend 👌 Feel free to submit a PR if you like!
The log fading one is strange, in my case it looked much better. Do you see any problems in the code?

@Rimbaldo
Copy link
Author

I'm not an expert in coding, so I don't know if there's anything in the code about the log effect... But, in order to the fading effects to fit in my Attiny167's memory, I had to change the log values declaration to Const PROGMEM, like this. It then compiled normally as I was running out of memory. I'm also using 1MHz on my attiny167, but even in an attiny85 at 16.5Mhz, in it's built-in led at P1 (pin 1) the effect was the same way really flickering strange.

const PROGMEM uint8_t LED_LOG_CURVE[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 18, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 30, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69, 71, 72, 74, 76, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98,100,102,105,107,109,112,114,117,119,122,124,127, 130,133,136,139,142,145,148,151,155,158,162,165,169,172,176,180, 184,188,192,196,201,205,210,214,219,224,229,234,239,244,250,255, };

One more thing I have just added is to change the range on the fly:

void setRange(int frange) { range_ = frange; }

So, as I'm using a bicolor led, green and red, with the same value of resistors for both colors,, the green is much stronger than the red. So when I want a perfect "Yellow" I decrease the range of the green, keeping the range of the red higher, and then a nice yellow appears on my button cap!

Is that a correct approach?

Regards, Rodrigo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants