I'm trying to use this guide for the button debounce Arduino - Button - Debounce | Arduino Tutorial (arduinogetstarted.com) on my arduino. The idea is when I press the button the code on void.setup run once, and then when I press the button again the rest of the code on void.setup is executed.
My problem with the debounce code is that none of my code is on void.loop and what I can do to make the debounce code run on void.setup instead of running on void.loop?
#include <ezButton.h>
ezButton button(7); // create ezButton object that attach to pin 7;
void setup() {
Serial.begin(9600);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
}
void loop() {
button.loop(); // MUST call the loop() function first
if(button.isPressed())
Serial.println("The button is pressed");
if(button.isReleased())
Serial.println("The button is released");
}