Debounce an LED, read and write analog I/O to that LED.

Hi there. I’m trying to switch ON an LED when I press a pushbutton and switch it OFF when I press it pushbutton again. When the LED is ON, I want to adjust the brightness using a potentiometer. I attempted to write a program to implement this but the button will switch ON the LED if the potentiometer is at minimum resistance and when I press the button again the LED wont go OFF. Can you please look at what I am doing wrong?? Thanks :wink:

Capture.PNG

Image from Original Post so we don't have to download it. See this Simple Image Guide

Capture.PNG

...R

Please don’t post pictures of text. Just copy and paste the program and use the code button </>. That way other people can try your program on their Arduino.

Also. please post the complete program. The problem is often in the other part.

…R

Oh…sorry. Thanks

program.ino (623 Bytes)

You are stuck forever in the while loop; read the buttonPin in the while statement and make the ledState LOW.

JMeller:
You are stuck forever in the while loop; read the buttonPin in the while statement and make the ledState LOW.

...or use the loop function to . . . loop.

AWOL:
...or use the loop function to . . . loop.

... even better.

Posting code, in code tags of course, is preferable to attaching it.

I attached the code after. Sorry about that. I'm New.

AWOL

I'm New.

That is why we have posts telling you how to use this forum. It is cunningly disguised under the rather misleading name of “how to use this forum “ because it tells you how to use this forum. Why do so many beginners not read this?

Is it that we hide it away as the first sticky posts in every section? Have you a suggestion where we could put it so fewer people are arsed to read it?

Parts of my anatomy do not count.

Grumpy_Mike:
Parts of my anatomy do not count.

LMAO!
Nothing against Lloyd - but, one has to appreciate the humor.