/********* 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 Actions"
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2024-06-17 00:16:49

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Implement a system using the EasyButton library to */
	/* detect single and long presses on a push button */
	/* connected to pin D2, triggering specific actions */
	/* for each event. */
/****** END SYSTEM REQUIREMENTS *****/

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

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

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t mybutton_PushButton_PIN_D2 = 2;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button(mybutton_PushButton_PIN_D2);  // Initialize the EasyButton instance with the pin number

void setup(void)
{
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize the button
  button.begin();
  
  // Add the callback function to be called when the button is pressed
  button.onPressed(onPressed);

  // Add the callback function to be called when the button is pressed for at least the given time
  button.onPressedFor(2000, onPressedForDuration);
}

void loop(void)
{
  // Continuously read the status of the button
  button.read();
}

// Callback function to be called when the button is pressed
void onPressed()
{
  // Code to be executed when the button is pressed
  Serial.println("Button pressed");
}

// Callback function to be called when the button is pressed for the given duration
void onPressedForDuration()
{
  // Code to be executed when the button is pressed for the given duration
  Serial.println("Button pressed for 2 seconds");
}

/* END CODE */