How can I use PWM in atmega16 with another ports (for example: PB0, PB1, PA0, etc.) and show the LED fade in and out slowly?
I tried to do it but the LED only duffenly turn on-turn off, not fade in-fade out.
How can I use PWM in atmega16 with another ports (for example: PB0, PB1, PA0, etc.) and show the LED fade in and out slowly?
I tried to do it but the LED only duffenly turn on-turn off, not fade in-fade out.
PWM gives you control over the average brightness of the LED by varying the duty cycle. This does not automatically mean the LED will 'fade on' or 'fade off'. This means that when you change the duty cycle, the LED brightness will 'instantaneously' change (well, not really instantly, but it will look like it with a sufficiently high PWM frequency). If you want to do a fade in or fade out, you will need to vary the duty cycle over a period of time. Perhaps you could make a loop that runs for 1000 iterations, each one increasing or decreasing the duty cycle a little bit and waiting 1 ms. This will produce a 1 second long fade. However, maybe a linear fade doesn't look all that nice - instead of updating the duty cycle directly, you can increment an accumulator variable and then run that through some sort of a mathematical function (say, the sine function) to smooth it out a bit. I believe the standard fading blink on most Macs is actually some sort of a smooth curve (possibly a sine or cosine, or perhaps just a parabola).