#include <mechButton.h>
#include <timeObj.h>

#define BTN_PIN     2     // Pin we'll hook the button to. The other side hooks to ground.
#define SOL_PIN    13     // Shows the solenoid activity.
#define REV_PIN    12    // Shows the reverse solenoid activity. 

#define BTN_PIN2    3
#define SOL_PIN2    11     // Shows the solenoid activity.
#define REV_PIN2    10

mechButton  aButton(BTN_PIN);             // Set button to pin BTN_PIN.
mechButton  anotherButton(BTN_PIN2);
timeObj     timeOutTimer(1000,false);     // Set to the miliseconds to time out.
timeObj     revTimeOutTimer(1000,false);  // Set to the miliseconds to time out.
timeObj     timeOutTimer2(1000,false);     // Set to the miliseconds to time out.
timeObj     revTimeOutTimer2(1000,false);  // Set to the miliseconds to time out.

void setup() {
   
    pinMode(SOL_PIN,OUTPUT);          // Set up the LED pin for output.
    pinMode(REV_PIN,OUTPUT);          // Set up the Reverse LED pin for output.
     pinMode(SOL_PIN2,OUTPUT);          // Set up the LED pin for output.
    pinMode(REV_PIN2,OUTPUT);          // Set up the Reverse LED pin for output.
    aButton.setCallback(myCallback);  // Set up our callback. (Also calls hookup() for idling.)
    anotherButton.setCallback(myCallback2);
}


// This is the guy that's called when the button changes state.
void myCallback(void) {

  if (!aButton.getState()) {      // We act if pin goes low.
    digitalWrite(SOL_PIN,HIGH);   // Turn solenoid on.
    timeOutTimer.start();         // Start the timeout timer.
  } else {
    digitalWrite(REV_PIN,HIGH);   // Turn reverse solenoid on.
    revTimeOutTimer.start();      // Start the reverse timeout timer.
  }
}


// This is the guy that's called when the button changes state.
void myCallback2(void) {

  if (!anotherButton.getState()) {   // We act if pin goes low.
    digitalWrite(SOL_PIN2,HIGH);     // Turn solenoid on.
    timeOutTimer2.start();         // Start the timeout timer.
  } else {
    digitalWrite(REV_PIN2,HIGH);   // Turn reverse solenoid on.
    revTimeOutTimer2.start();     // Start the reverse timeout timer.
  }
}


// Your standard sketch loop()
void loop() {

  idle();											    // Let all the idlers have time to do their thing.
  if (timeOutTimer.ding()) {      // If the timeout timer expires..
    digitalWrite(SOL_PIN,LOW);    // Shut off the solenoid.
    timeOutTimer.reset();         // Reset the timer.
  }
  if (revTimeOutTimer.ding()) {   // If the reverse timeout timer expires..
    digitalWrite(REV_PIN,LOW);    // Shut off the reverse solenoid.
    revTimeOutTimer.reset();      // Reset the timer.
  }
  if (timeOutTimer2.ding()) {      // If the timeout timer expires..
    digitalWrite(SOL_PIN2,LOW);    // Shut off the solenoid.
    timeOutTimer2.reset();         // Reset the timer.
  }
  if (revTimeOutTimer2.ding()) {   // If the reverse timeout timer expires..
    digitalWrite(REV_PIN2,LOW);    // Shut off the reverse solenoid.
    revTimeOutTimer2.reset();      // Reset the timer.
  }
}