I have a project, where I use long-press, to activate and deactivate the function af the program. (From line 160)
It all works great, BUT when it have been activated (TrapActive = 1) and i let it be turned on for more than 30-60 min, it goes to "TrapActive = 0" unless I hold down the button. It will not switch with long-press, only while I hold down the button.
Tried deactivating sleep, and it all works great for hours with no problem, so I think the problem might have to do with millis during sleep, but I'm not shure why, as i thought sleep only "paused" the program?
Any help is appreciated - alternative ways of doing the long-press, if that is the problem.
The code is used on a custom-board with a 328p at 8mHz without crystal, and no serial connection.
I don't know if you are focused on the right part of your program.
Jeg kan ikke læse dansk for lort. (edit: Idiom doesn't translate well) I don't read Danish very well. Your program is incomplete, it won't compile besides also being 500 lines long.
I have expended my budget for this problem. I did observe some things wrong with your button handling.
In lines 168 - 180, if you mean to be debouncing the CaseSw pushbutton I believe you have failed.
Here is your code with some fixes, just the part that reads the CaseSw pushbutton, debounces it and recognizes a long press.
I tried to not damage your code. I eliminated, to an extent possible, everything that had nothing to do with that pushbutton. I added some print statements and legitimized the debouncing.
If you spend 1/4 the time I have spent looking at your code looking at mine, you may see what I am getting at.
I don't think the sleep enters into it. millis() should just stall like all progress through your code. But I did by no means analyze your entire program. I noticed that the button press and long press could be isolated and tested (fixed!). Which is what I would have suggested you do - divide and conquer!
I hope this hepls.
BTW during testing I made the long press 700 ms. 3000 ms is a very long pres and feels like an eternity during testing, at least to someone with not so much time left.
It was is no way my intention, to have anybody fix my problem - only to give some hint about what could be wrong.
This code is not written all in one go, thats why I know it began when the watchDog timer was enabled.
I use Visual studio, and the last copy to pasteBin did not include a "folded" void, but here is a complete one: https://pastebin.com/dNmnhqEp
This one works flawlessly, as I have commented out line 358 - 368, which include 399 - 417 - Then all works, except it only wakes in pin interupts - not via the WatchDogTimer.