Hello I've learn a lot from this comunity. This is mty first post
I have a problem with a project I'm trying to add a timer for an output ex. LED. The thought is If push button1 then set Led High for 20min or If I push it again set Led LOW.
I' ve got this code and I do not want to use delay, becaouse I have an LCD that takes data from a temp sensor.
int pinButton = 2;
int LED = 6;
int stateLED = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 700;
Why do you care if previous equals stateButton, when you don't do anything either way?
There does NOT appear to be any relationship between previous and stateButtton, so it is not obvious why you are comparing them. currentState and previousState DO appear to be related.
Split it into separate parts. A turn on (led is off and button becomes pressed) and a turn off (led is on and (time elapsed or button becomes pressed)).
And if you want easy, grab a library to handle the button debounce and state change detection like Bounce2.