Another timer problem, 3 push button timer.

I have three rugged metal push buttons. One is a reset button connected to the reset pin. NOTE: I do not have have any code written for it for the external reset button pin , it is working just fine. The start/stop buttons both are normally open and connected to pin 7"Start" and pin 6"stop". The arduino is connected to a standard 16x2 lcd matrix, no problems here either, the screen works fine.

My problem is I want to start the for loop when I press the start button and display the time in seconds. When I press the stop button I want the current time to be displayed until the reset button is pressed then wait until the start is pressed again to begin timer at 0. The LCD diplays 00 mins 00 sec but, its not counting. Here is my code.

#include <LiquidCrystal.h>
const int startButton = 7;
const int stopButton = 6;
//Reset button is connected to reset pin

int buttonStatus1 = LOW;//both buttons are set to normally open
int buttonStatus2 = LOW;
bool state = HIGH;//state is set to high for my boolean comparison


const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

signed short minutes, seconds = 0;

char timeline[16];

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("Start Time");
  
  
  lcd.print("Press Green Button");// this is printing
  pinMode(startButton, INPUT);//I am using a 330 ohm pull-down resistor
  pinMode(stopButton, INPUT);
 }
void loop() {
   lcd.setCursor(0, 1);
  sprintf(timeline,"%0.2d mins %0.2d secs", minutes, seconds);
  lcd.print(timeline);
  
  if(digitalRead(startButton) == state && (digitalRead(stopButton) != state)) {
    lcd.clear();
    int i = seconds;   
    int m = minutes;
    
    for(i; i<=60; i++){
     delay(1000);
   sprintf(timeline, "%0.2d mins %0.2d secs");
     }
    if (i == 60)
    {
      i = 0;
      m++;
       sprintf(timeline, "%0.2d mins %0.2d secs");
    }

   if (digitalRead(startButton) != state && (digitalRead(stopButton) == state)) {
    
    lcd.clear();
    delay(100);
    lcd.print(minutes,seconds);

   }
  }
}

Thanks :slight_smile:

The sequence of operations you have at the moment is all wrong.

When the start button is pressed set a Boolean variable called perhaps counting to true, and when the stop button is pressed set this to false. Then only update the display when the variable counting is true. Use an if statement for this.