CCCPaste

Button Example 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 Example
	- Source Code NOT compiled for: Arduino Mega
	- Source Code created on: 2024-10-26 19:51:02

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Implement a push button interface using EasyButton */
	/* library to detect button presses on digital pin */
	/* D2, ensuring reliable input handling with pull-up */
	/* resistor configuration. */
/****** 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 PUSH_PushButton_PIN_D2 = 2; // Define the pin for the push button

/***** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
// Create an instance of EasyButton for the push button
EasyButton pushButton(PUSH_PushButton_PIN_D2, 35, true, true); // Initialize EasyButton with the pin number, debounce time, pull-up enabled, and active low

// Function to be called when the button is pressed
void onPushButtonPressed() {
    Serial.println("Push button pressed"); // Print message to Serial Monitor
}

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

    // Print a message to indicate setup is complete
    Serial.println();
    Serial.println(">>> EasyButton example <<<");

    // Initialize the push button
    pushButton.begin(); // Call begin() to set up the button
    pushButton.onPressed(onPushButtonPressed); // Attach the onPressed event handler

    // Set the pin mode for the push button
    // The pin mode is already handled by EasyButton's begin() method with pull-up enabled
}

void loop(void) {
    // Continuously read the button state
    pushButton.read(); // Call read() to check the button state
}

/* END CODE */