As a result, it is a common task that an embedded program needs to interpret buttons. Let us assume pin 5 of port A is configured as an input pin with internal pull up. You should already know by now that the configuration code for this pin should be as follows (assuming all other pins are already configured):
DDRA &= ~(1 << 5); PORTA |= 1 << 5;
To call button_down when the button is pressed, and
call button_up when the button is released, we can use the
following code:
if (PINA & (1 << 5)) button_up(); else button_down();
This works if you only want to know the current state of a button. However, often we need to know a change of state, rather than the current state. In other words, a program may not be interested at all in whether a button is pressed or released, but when the button is being pushed or released.
There are two techniques to detect the ``edge'' of a binary signal change. The first method is called busy polling, whereas the second does not have an actual technical name.