Sleep and long-press button

Hello

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.

Code here: https://pastebin.com/j4yNVypL
Edit:
From line 160: the long-press code
From line 352: the sleep code

TIA - Jesper

I think line 172 should be moved to line 169.5, that is to say between 169 and 170.

a7

I see why it could be a problem, but tried it, and it does not change the behavior

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. :expressionless:

a7

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.