Hello RossW,
Ross>>I'm trying to code a circuit that will gradually 'fade' out an LED. This is an illusion, mind you, as naturally and LED is either high or low. Someone mentioned that they can simulate this using a 5 channel PWM circuit, but I haven't a clue what they're talking about.
Does anyone have any ideas, or even better, some sample code?<<
Well a PWM just varies the width of a pulse between 0 and 256 (256 being steady output). And the PWM can work while other things are going on in your chip...
You can simulate a PWM, or you can use a PWM... A easy way to make a dimmer, is to vary the number of times the 5 volts is applied to the light.
LED var byte.
Counter var byte
Counter2 var byte
Counter3 var bye
For Counter= 256 1 step -1
For Counter2=1 to 256
For Counter3=1 to 256
LED high 'turn on LED
Pause Counter 'wait a while
LED Low 'turn off LED
Next counter3
Next counter2
Next Counter
Though I have not check this out, I think it will work for you.
It is based upon the principal that your eye is not as fast as we wish. You can change the variables to words and save some code.. and get rid of a for-next statement. I am sure there are other ways to accomplish this... but my mind is tired, and this was the easiest way I thought of off the top of my head.
Dwayne
Ability to Fly:
Hurling yourself towards the ground, and missing.
Engineers that Contribute to flying:
Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute
Pilots that are Flying:
Those who know their limitations, and respect the green side of the grass...
Bookmarks