I am thinking of using a timed button press to determine which branch of code to enter (I want to make a secret menu that appears on the screen after a button is held for 5 seconds).
What is the best way to accomplish this? I saw an old post about this but am not sure:
where to put the timer/how to capture the time (the example link in the old post was broken)
if interrupt driven DateTime.Now differences are better than a timer
if there is a better way to accomplish entering my “secret menu”
I have 5 buttons on my device, all are interrupt low driven. If I did an interrupt timer, would I have to sacrifice one of these buttons to set it to both edges? I can always add another dedicated menu button if this turns out to be unreliable/a pain.
Poll the button’s pin at 1 second intervals. Increment counter on each poll, if button is 0 then clear counter. If exactly 5 then trigger event. Otherwise let the counter keep counting.
I should note: preference given to solution that does not require an additional interrupt. I would like to be able to piggy back all this on an existing one and not have to dispose of configurations. I currently have 5 edge low interrupts. If I have to configure one as both edges, it will be hard to maintain functionality in the other stages of my program
rig one of my existing interrupt edge low buttons so that if it is held instead of quickly pressed, a flag is raised to enter a secret branch of code. Must stay away from having to switch the button type/configuration because this button needs to work throughout the whole program (like in places where edgelow is needed)
Because later in the program that same button will be needed as interrupt edge low while still maintaining the ability to access the menu. But it is seems to be overly complicated as I anticipated, I am just going to add an extra button dedicated to accessing the menu. This whole menu concept on a 20x2 character display is quite a challenge lol
The sequence I described would allow a single button to both access the secret menu and its normal functionality. Just that button would need interrupts on rising and falling edges. Does not seem complicated to me.
Try a sample program, and see if it works for you.
@Mike In your code, won’t that button count 1 press as 2 presses during normal functionality since it is interrupt edge both? That is why I said I didn’t think it would work.
Also, can you please explain to me how the interrupt inputs work? I never fully understood that part and have never seen port or state inputs like that…might be useful for me
Busy right now… Will explain interrupt handler later.
There should not be a problem with two interrupts per press/release since you know there are two interrupts per press, and should be able to handle it. From the state variable, you should be able to recognize press or release.
Play with the code and see how it works.
As for port and state… this is actually what the passed parameters of the interrupt mean. It appears in the GHI document on InterruptPorts.
What if “Secret Menu” is an understatement and if the wrong eyes were to fall upon this menu we could risk global economic collapses like the world has never seen?
Then you have back up fail-safe solutions I suppose. I have never had a device I can recall (that I used often) with which I did not get an unregistered button state change at least once.
I’m still Team Polling anyway. If you aren’t absolutely sure interrupts are better for your app than polling then you should IMO poll for better performance (of the buttons) and easier development. I know there are major advantages to interrupts (or these psuedo-interrupts) but weigh them against the ease of polling!