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

#define PULSE_PIN 2     // Pin we'll hook the button to. The other side hooks to ground.
#define PUMP_PIN	13    // Shows the pump activity. 

mechButton  aButton(PULSE_PIN); // Set button to pin PULSE_PIN.
timeObj     timeOutTimer(1000); // Set to the milisecond to time out. Change to 20ms?


void setup() {
   
   pinMode(PUMP_PIN,OUTPUT);				// Set up the LED pin for output.
   aButton.setCallback(myCallback); // Set up our callback. (Also calls hookup() for idling.)
}


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

   if (!aButton.getState()) {       // We act if pin goes low. Change yours to High?
      digitalWrite(PUMP_PIN,HIGH);  // Turn pump on.
      timeOutTimer.start();         // Start the 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(PUMP_PIN,LOW);   // Shut off the pump.
    timeOutTimer.reset();         // Reset the timer.
  }
}