fading in and out led

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

fading in and out led

Post 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.
Attachments
fade in led.fcfx
(9.12 KiB) Downloaded 260 times

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: fading in and out led

Post 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
Success always occurs in private and failure in full view.

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: fading in and out led

Post 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!

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: fading in and out led

Post 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
Attachments
fade in led1.fcfx
(10 KiB) Downloaded 243 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: fading in and out led

Post 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 8)

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.

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: fading in and out led

Post 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.

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: fading in and out led

Post 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 8)

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..

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: fading in and out led

Post by Benj »

Here's a quick example.
Fibonacci_LUT.fcfx
(10.68 KiB) Downloaded 252 times
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.

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: fading in and out led

Post by DavidA »

I found issue causing the articles not to shown.

https://www.matrixtsl.com/article.php?a=365

'Should' work now.

Post Reply