Turning an LED on and off with a push-button
In contrast to a PC, where the keyboard, mouse, or touchscreen facilitates human interactions with software applications, the physical button represents the most common way to interact with a microcontroller.
In this recipe, we will learn how to integrate a push-button into the electronic circuit built in the previous recipe. Then, we will employ the GPIO peripheral to detect whether the button is pushed or released and use this information to control the LED light.
Getting ready
Before diving into the practical part of this recipe, let’s start by introducing the operating principles of the push-button.
The operating principles of the push-button
From an electronics point of view, a push-button is a device that makes (a.k.a. shorts) or breaks (a.k.a. opens) the connection between two wires. When we press the button, we connect the wires through a mechanical system, allowing the current to flow. However, unlike...