Page 1 of 1
PWM LED Control
Posted: Fri Oct 21, 2016 10:22 am
by Zalat88
Hi everybody.
I have a problem with PWM.
I want to control the brightness of LED with one button and PWM. For example: when I push a button for a 3 sec.Led should be smoothly light, else when I push fast for 1 ms LED should light instantly,
maybe someone can help me??

Re: PWM LED Control
Posted: Fri Oct 21, 2016 12:57 pm
by Benj
Hi Zalat,
I have split your post onto a new thread so it doesn't hijack the last topic.
Have you had a go at the problem yourself? If you post your code so far then we can help suggest ways to improve of fix things.
You don't state what hardware you're using i.e. which chip.
Re: PWM LED Control
Posted: Mon Oct 24, 2016 4:14 am
by Zalat88
Hello Mr.Benj
thanks for reply
ok, I'll put my project
I use atmega 328p
Re: PWM LED Control
Posted: Mon Oct 24, 2016 7:36 am
by Zalat88
Zalat88 wrote:Hello Mr.Benj
thanks for reply
ok, I'll put my project
I use atmega 328p
Re: PWM LED Control
Posted: Mon Oct 24, 2016 3:02 pm
by Benj
Here you go, This should allow you to switch the LED on and off with ramp up and ramp down while the switch is held.
You may find the LED reaches full brightness around 50% duty. To help give a better range you could lower your PWM frequency (which may help somewhat but could lead to noticeable flicker) or you could increase the delay in the loop.
To save power you could make 128 the new maximum duty value e.g. the LED looks just as bright but actually it's off for half of the time saving 50% power.