#include <ezButton.h>

const byte button1Pin = 2;
const byte button2Pin = 3;
const byte led1Pin = 4;
const byte led2Pin = 5;

bool sequenceDone = false;

ezButton button1(2);  
ezButton button2(3);  

int button1State;            // the current reading from the input pin
int button2State;            // the current reading from the input pin

enum { ONE, TWO, BOTH, REJECT, NONE } lastState = NONE;
String oneMsg = "One";
String oneModMsg = "One-Modified";
String twoMsg = "Two";
String twoModMsg = "Two-Modified";

void setup() {
  pinMode(led1Pin, INPUT);
  pinMode(led2Pin, INPUT);
  button1.setDebounceTime(50); // set debounce time to 50 milliseconds
  button2.setDebounceTime(50); // set debounce time to 50 milliseconds
  Serial.begin(9600);
  Serial.setTimeout(10);
}

void loop() {
 button1.loop(); // MUST call the loop() function first
 button2.loop(); // MUST call the loop() function first
 digitalWrite(led1Pin, button1State);
 digitalWrite(led2Pin, button2State);
 if (ButtonStateUpdate())
 {
  if (lastState == REJECT)
  {
    if (button1State == LOW && button2State == LOW)
    {
      Send("Reject to none");
      lastState == NONE;
    }
    return;
  }
  if (button1State == HIGH && button2State == HIGH)
  {
    Send("Set Both");
    lastState = BOTH;
    return;
  }
  if (button1State == LOW && lastState == BOTH)
  {
    Send("Both to Reject");
    Send(oneModMsg);
    lastState = REJECT;
    return;
  }
  if (button1State == LOW && lastState == ONE)
  {
    Send(oneMsg);
    Send("One to Reject");
    lastState = REJECT;
    return;
  }
  if (button2State == LOW && lastState == BOTH)
  {
    Send("Both to Reject");
    Send(twoModMsg);
    lastState = REJECT;
    return;
  }
  if (button2State == LOW && lastState == TWO)
  {
    Send("Two to Reject");
    Send(twoMsg);
    lastState = REJECT;
    return;
  }
  if (button1State == HIGH && lastState == NONE)
  {
    Send("One");
    lastState = ONE;
    return;
  }
  if (button2State == HIGH && lastState == NONE)
  {
    Send("Two");
    lastState = TWO;
    return;
  }
  Send("End of change event");
 }
}

void Send(String msg)
{
  Serial.println(msg);
}
bool ButtonStateUpdate() {
  int btn1State = button1.getState();
  int btn2State = button2.getState();
  bool hasChanged = false;
  if (btn1State != button1State)
  {
    button1State = btn1State;
    hasChanged = true;
  }
  if (btn2State != button2State)
  {
    button2State = btn2State;
    hasChanged = true;
  }
  return hasChanged;
}