This code should work. You will need to declare the following variables:
- lastPress // The last time the button was pressed
- outputState // The state of the timed output
- outputPin // The pin number for the timed output
- PERIOD // The amount of time that the outptu remains on
The code:
void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledOn = !ledOn;
buttonPresses++;
lcd.clear();
lcd.print("Number of Button ");
lcd.setCursor(0,1);
lcd.print("Presses = ");
lcd.print(buttonPresses);
outputState = HIGH;
lastPress = millis();
}
if (outputState && ((millis() - lastPress) > PERIOD))
{
outputState = LOW;
}
digitalWrite(outputPin, outputState);
lastButton = currentButton;
digitalWrite(ledPin, ledOn);
}
A relay should be used to drive a pump etc.. The Arduino Uno can only drive 5V at maximum 20mA.