Hi, im building an application with a lot of loops and subroutines and I need to know every now and then if a button has been pressed.

I know that this can be accomplished by reading the port as often is possible, but I tought that by latching the port, when I have time to look at it and view if it changed from the last time it would be easier for my program structure.

to be clear, here is the metacode:

buton state=0
loop:
program runs
button is pressed (new state=1), buttons keeps this state
program continues
button is sensed and checked if it changed
loop

I know that at any given time the button may be pressed twice and I could miss that. This is something I can live with.

is there a simple way of accomplishing this?

thanks