Pages: [1]   Go Down
Author Topic: Fade PWM in (almost) realtime.  (Read 448 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a clock setup that is changing LED brightness according to the  last number in the seconds value.  this number can be 0 to 5.  So to get the PWM i have done this...

TimeInPWM = map (TimeFromRTC,  0, 5, 0, 255);

This gives me a LED that brightness can tell you the value of the ones digit that represents the current second.

I am trying to find a way to have the led fade from one value to another instead of have it jump exactly on the second tick.  Any thought on how i can accomplish this ?
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12523
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Presumably you know how long it takes for the last number in the seconds value to increment by one, so can't you just ramp up the brightness at the appropriate speed based on elapsed time?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can use a For loop, but  i run the  danger of the loop taking longer to complete than the clock takes to cycle  if i only increment by one.  I could  do larger increments but loose resolution.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12523
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can use a For loop, but  i run the  danger of the loop taking longer to complete than the clock takes to cycle  if i only increment by one.  I could  do larger increments but loose resolution.

Decide how many steps you want to have i.e. how smoothly you want the change to occur and then work out how long an interval you need between each step, and then alter the value by one step at that interval.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: