CCCPaste

"Button Callbacks" rev_03

/********* 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 Callbacks"
	- Source Code NOT compiled for: Arduino Pro Mini 3.3V
	- Source Code created on: 2024-06-16 13:22:18

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Implement a system to detect button presses using */
	/* EasyButton library. Utilize digital pins D2 and D3 */
	/* as input pins for two push buttons. Ensure the */
	/* system initializes pins in setup() and */
	/* continuously checks button states in loop(). */
/****** END SYSTEM REQUIREMENTS *****/


/********* User code review feedback **********
#### Feedback 1 ####
- PYHON GAME COLORY

********* User code review feedback **********/

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

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

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t XXMX_PushButton_PIN_D2 = 2;
const uint8_t XXMX_PushButton_PIN_D3 = 3;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button1(XXMX_PushButton_PIN_D2);  // Initialize EasyButton object for button1
EasyButton button2(XXMX_PushButton_PIN_D3);  // Initialize EasyButton object for button2

void onButton1Pressed() {
  Serial.println("Button1 pressed");
}

void onButton2Pressed() {
  Serial.println("Button2 pressed");
}

void setup(void) {
  // Initialize serial communication
  Serial.begin(115200);
  Serial.println();
  Serial.println(">>> EasyButton multiple buttons example <<<");

  // Initialize buttons
  button1.begin();  // Initialize button1
  button2.begin();  // Initialize button2

  // Attach callback functions for button presses
  button1.onPressed(onButton1Pressed);  // Attach callback for button1
  button2.onPressed(onButton2Pressed);  // Attach callback for button2
}

void loop(void) {
  // Continuously check the state of the buttons
  button1.read();  // Read the state of button1
  button2.read();  // Read the state of button2
}

/* END CODE */