PWM LED Control

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

Moderator: Benj

Post Reply
Zalat88
Posts: 7
Joined: Thu Aug 04, 2016 11:13 am
Has thanked: 2 times

PWM LED Control

Post 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??
:?: :?:

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: PWM LED Control

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

Zalat88
Posts: 7
Joined: Thu Aug 04, 2016 11:13 am
Has thanked: 2 times

Re: PWM LED Control

Post by Zalat88 »

Hello Mr.Benj
thanks for reply
ok, I'll put my project
I use atmega 328p

Zalat88
Posts: 7
Joined: Thu Aug 04, 2016 11:13 am
Has thanked: 2 times

Re: PWM LED Control

Post by Zalat88 »

Zalat88 wrote:Hello Mr.Benj
thanks for reply
ok, I'll put my project
I use atmega 328p
Attachments
PWM_BUTTON_328.fcf_avr
(15.63 KiB) Downloaded 322 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: PWM LED Control

Post 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.
PWM_BUTTON_328_v7.fcfx
(10.94 KiB) Downloaded 364 times
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.

Post Reply