CCCPaste

Button Detection rev_01

/********* 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 NOT compiled for: Arduino Uno
	- Source Code created on: 2024-08-25 09:48:21

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* HUMANIZE THE OCDE GIVEN */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 	// https://github.com/evert-arias/EasyButton

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t MYBUTTON_PushButton_PIN_D2 = 2; // Define the pin number for the push button

/***** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
// Create an instance of EasyButton for the defined pin
EasyButton myButton(MYBUTTON_PushButton_PIN_D2); // Initialize the EasyButton object for the button

// Callback function that gets called when the button is pressed
void onButtonPressed() {
    Serial.println("Button pressed"); // Print message to the Serial Monitor
}

void setup(void) {
    Serial.begin(115200); // Start serial communication at 115200 baud rate

    // Set the button pin mode to INPUT with an internal pull-up resistor
    pinMode(MYBUTTON_PushButton_PIN_D2, INPUT_PULLUP);

    // Initialize the EasyButton instance
    myButton.begin(); // Call begin() to set up the button

    // Attach the onPressed callback function to the button
    myButton.onPressed(onButtonPressed); // Set the callback for button press
}

void loop(void) {
    myButton.read(); // Continuously read the button state to detect presses
}

/* END CODE */