In our last program, we were checking if the button is pressed or not after each second. The button must remain pressed at the time of console printing to get it printed pressed
. If you press the button quickly in between two printings, it will still print released
. So in this situation, one button press event is lost. Consider another scenario. It is possible that nobody pressed the button for a long time. But still the program will wake up every 1 second and check for pin values. This is called polling. It wastes lots of CPU time and system resources on repetitive checking. This is not good programming practice. Polling prevents the CPU from going to sleep and saves power. This is not good for embedded systems where the battery power is crucial. Also, you cannot respond well to high frequency input signals using polling.
To solve this problem, some I/O devices/components are allowed to notify the CPU when a specific event occurs. These events are like a touch being...