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

#define PULSE_PIN 2     // Pin we'll hook the button to. The other side hooks to ground.
#define THING_PIN	13    // Shows the thing 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(THING_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(THING_PIN,HIGH);   // Turn thing 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(THING_PIN,LOW);    // Shut off the pump.
    timeOutTimer.reset();           // Reset the timer.
  }
}