Skip to main content
Post Undeleted by sa_leinad
added 1100 characters in body
Source Link
sa_leinad
  • 3.2k
  • 2
  • 24
  • 53

if (flag && ((now - then) > PERIOD)) {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.

if (flag && ((now - then) > PERIOD)) {

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.

Post Deleted by sa_leinad
Source Link
sa_leinad
  • 3.2k
  • 2
  • 24
  • 53

if (flag && ((now - then) > PERIOD)) {