Page 1 of 1
fading in and out led
Posted: Sat Sep 08, 2018 8:31 am
by Dutch
Hi Everybody,
Im with fun doing all kind of simple programming and I may say I do get my programs running one way or the other.
but now im stuck in something maybe not so important seeing all the harder questions here, but there must be a way. and something simple now and then makes it fun...
I made a loop running 255 times in a programmable led and added each loop a variable is added to the PWM of the led, and a delay so it appears it fades in in brightness.
it does work in the simulation here in flowcode but of coarse our eye is seeing much more difference in say a value 1-10 for the PWM or even 1-100 on the scale of 255 max.
I tried to add in a kind of logarithmic variable or even a second variable in the delay but im not succeeding...
is there a mathematic genius here who can tell me how to add small numbers in the start and larger steps in the end? I have found a log calculation in fc but don't know how to add it and try.
Thanks, Angelo.
Re: fading in and out led
Posted: Sat Sep 08, 2018 9:26 am
by Steve001
Hi Dutch
There was a project some time ago (V4) if you do a search "mood light" the article zone gives a 404 error for some reason hopefully matrix staff will see this and try and fix the broken link.
viewtopic.php?f=36&t=7021&hilit=mood+light
this post may be of some use also
viewtopic.php?f=54&t=14888
Steve
Re: fading in and out led
Posted: Sat Sep 08, 2018 10:28 am
by Dutch
I get the same error on that first link. but maybe the posted code I can open.
the second I have to see if parts work in my project. I see real pwm used while I create it with variable timings for led on and a fixed off.
Thanks for your response!
Re: fading in and out led
Posted: Sat Sep 08, 2018 7:21 pm
by jgu1
Hi Dutch!
I dont know if I understand you correct, I I think you mean when the led has to ligth up, you want it more linear.
I made some changes in your program. The led will ligth up fastere in the beginning and slower in the end.
Hope you can see the idea in the program. You can add some more desicions IF and split it more up.
Br Jorgen
Re: fading in and out led
Posted: Sat Sep 08, 2018 10:52 pm
by Benj
I'm not sure how well this would work but you could maybe try the Fibonacci sequence. Store the values for the sequence in a look up table component and reference the values with an incrementing or decrementing index variable. I can provide a demo of needed
I'm not sure if you would use the value for the pwm duty or the delay between values or both. Maybe start with just the duty and see how you get on.
Re: fading in and out led
Posted: Mon Sep 10, 2018 6:48 am
by Dutch
jgu1 wrote:Hi Dutch!
I dont know if I understand you correct, I I think you mean when the led has to ligth up, you want it more linear.
I made some changes in your program. The led will ligth up fastere in the beginning and slower in the end.
Hope you can see the idea in the program. You can add some more desicions IF and split it more up.
Br Jorgen
Hmm more linear to our eye but that is indeed less larger incements in the start and faster in the end.
What you made is a possibility. didn't think of that because its a little rough jumps but maybe good enough for a visual effect! going to play with that idea a bit! thanks.
Re: fading in and out led
Posted: Mon Sep 10, 2018 6:52 am
by Dutch
Benj wrote:I'm not sure how well this would work but you could maybe try the Fibonacci sequence. Store the values for the sequence in a look up table component and reference the values with an incrementing or decrementing index variable. I can provide a demo of needed
I'm not sure if you would use the value for the pwm duty or the delay between values or both. Maybe start with just the duty and see how you get on.
If you could make a simple example how to get a value out of a lookup table that would be great. learning on the job
il try to extrapolate values for red for the human eye then.. it might look like a logarithmic scale..
Re: fading in and out led
Posted: Mon Sep 10, 2018 9:47 am
by Benj
Here's a quick example.
Fibonacci is otherwise known as natural log I believe. We could use the log function instead of the LUT but this adds a lot of processing overhead dealing with the floating point maths.
Re: fading in and out led
Posted: Tue Sep 11, 2018 3:09 pm
by DavidA
I found issue causing the articles not to shown.
https://www.flowcode.co.uk/article.php?a=365
'Should' work now.