/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Button Detection" - Source Code compiled for: ESP32 DevKit V1 - Source Code created on: 2024-07-03 22:20:10 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* print on serial button state. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include //https://github.com/evert-arias/EasyButton /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void onPressed(void); // Prototype for the button press callback function /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t button_PushButton_PIN_D4 = 4; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button(button_PushButton_PIN_D4); // Initialize EasyButton object with the pin number void onPressed() { Serial.println("Button pressed"); // Callback function to handle button press } void setup(void) { // put your setup code here, to run once: Serial.begin(115200); // Initialize serial communication Serial.println(); Serial.println(">>> EasyButton pressed example <<<"); button.begin(); // Initialize the button button.onPressed(onPressed); // Attach the callback function to the button press event } void loop(void) { // put your main code here, to run repeatedly: button.read(); // Read the button state // Print the current button state if (button.isPressed()) { Serial.println("Button is currently pressed"); } else { Serial.println("Button is currently released"); } delay(100); // Add a small delay to avoid flooding the serial monitor } /* END CODE */