/*
  KeyPress_WithCallbackFunc.ino
  Created:  4-Mar-2023
  Author:   MicroBeaut

  The KeyPress event occurs when presses a key
*/

#include "RepeatButton.h"

#define buttonPin A0                 // Define the button input pin.

RepeatButton button;                // Decalre the RepeatButton object

void OnKeyChanged(ButtonEvents e);  // Declare the OnKeyPress Callback Function

void setup() {
  Serial.begin(115200);
  button.buttonMode(buttonPin, INPUT_PULLUP); // Set the button mode
  button.buttonEvents(OnKeyChanged);          // Configure the callback function event on the key pressed
  button.holdDelay(3000);
  button.repeatDelay(500, 250);
}

void loop() {
  button.repeatButton();                      // Executing the repeat button function
}

void OnKeyChanged(ButtonEvents e) {
  switch (e) {
    case PRESS:
      Serial.println("Callback Event on Key Pressed");  // Print message event on key pressed
      break;
    case RELEASE:
      Serial.println("Callback Event on Key Released");  // Print message event on key released
      break;
    case HOLD:
      Serial.println("Callback Event on Key Holding");  // Print message event on key released
      break;

    case REPEAT:
      Serial.println("Callback Event on Key repeating");  // Print message event on key repeating
      break;
  }
}