Including the Library
Once the library has been installed, you may include it as shown below.
The library exposes the EasyButton class. Create an instance of the class for every button that you have connected.
The following arguments can be passed to the class constructor.
|Argument||Data Type||Required?||Default Value||Description|
|pin||uint8_t||yes||n/a||Arduino pin number where the button is connected.|
|debounce_time||uint32_t||no||35||Period of time to make sure the pushbutton is definitely pressed. Please refer to debounce.|
|pullup_enable||bool||no||true||Enable internal pullup resistor. Please refer to digital pins. If using ESP32, please see the note below.|
|invert||bool||no||true||Invert button logic. If true, low = pressed else high = pressed. Please refer to invert.|
If using ESP32, be aware that some of the pins does not have software pull-up/pull-down functionalities. In that case, use an external pull-up resistor, 10K works well. Please refer to Pull-up Resistors.
Initializing a button
Initialize the button by calling the method
begin within the
Update Button State
Continuously read the state of the button.
Defining interruption service routine
Enabling external interrupt
EasyButton allows you to attach callback functions to certain button events. Use callback functions to run specific code when the event gets triggered. Attach callback functions within the setup function.