// You will need to install LC_baseTools
// from the library mananger to compile this.

#include <mechButton.h>               // Debounced button library.
#include <timeObj.h>                  // Easy to use timer object.

#define GREEN_LED   5                 // Green LED pin
#define RED_LED     4                 // Red LED pin

mechButton  greenBtn(3);              // Green button controller.
mechButton  redBtn(2);                // Red button controller.
timeObj     greenTimer(2000,false);   // Set to 2 sec. Change to 5 minutes.
timeObj     redTimer(2000,false);     // This one too. (They are floats, not ints)


void setup() {
  
  pinMode(GREEN_LED, OUTPUT);         // Green LED set to output.
  pinMode(RED_LED, OUTPUT);           // Red LED set to output.
  greenBtn.setCallback(greenBtnClk);  // If green button is clicked, call this function.
  redBtn.setCallback(redBtnClk);      // If red button is clicked, call this other function.
}


// When the green button is clicked, this gets called..
void greenBtnClk(void) {

  if (!greenBtn.getState()) {         // If the green button is grounded..
    digitalWrite(GREEN_LED,HIGH);     // Turn on the green LED.
    greenTimer.start();               // Start the green timer.
  }
}


// When the red button is clicked, this gets called..
void redBtnClk(void) {
  
  if (!redBtn.getState()) {         // If the red button is grounded..
    digitalWrite(RED_LED,HIGH);     // Turn on the red LED.
    redTimer.start();               // Start the red timer.
  } 
}


void loop() {

  idle();                           // idle() runs things in the background.
  if (greenTimer.ding()) {          // If the green timer has expired..
    digitalWrite(GREEN_LED,LOW);    // Shut off the green LED.
    greenTimer.reset();             // Reset the green timer.
  }
  if (redTimer.ding()) {            // If the red timer has expired..
    digitalWrite(RED_LED,LOW);      // Shut off the red LED.
    redTimer.reset();               // Reset the red timer.
  }   
}