if
mreadingis not the same aslastmachineStatethen you reset your debounce time so your very next if() statement will never be true AND you never updatelastmachineState
Sorry, that doesn't make any sense. If you refer to my first post, the code I used to start with, it starts that same way. I just created a second set of variables that mirror those original variables.
You should also break those two conditions apart. Check your machine on/off first, if it has changed, print your message.
If it is currently off, you can just
returnfrom loop() which skips the reset of loop() and goes back to the beginning. No need to worry about the LED if the machine is OFF.
That's what I assumed would be the correct course of action. I don't know how to structure it. I need to be shown what it looks like in order to understand it.