Button to stop a stopwatch not working correctly! I'm trying to implement a stopwatch with an LCD display, and I'm supposed to be using the attachInterrupt command to catch the button press. The clock runs perfectly, but the button input isn't caught or acted upon at all.
In void setup(), I have set it up this way: attachInterrupt(digitalPinToInterrupt(buttonPin), buttonInterrupt, RISING);.
And the buttonInterrupt function only does start = !start, so in a sense just flipping the start variable.
This is the updated version of the code:
#include &lt;LiquidCrystal.h&gt;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonPin = 7; 
volatile int buttonState; 
int lastButtonState;
long sec; 
long startTime;  

void setup() {
  lcd.begin(16, 2);
  pinMode(buttonPin, INPUT_PULLUP);
  lcd.setCursor(0,0);
  lcd.print(&quot;Push the button!&quot;);
  attachInterrupt(digitalPinToInterrupt(buttonPin),buttonInterrupt,HIGH);
}

void loop() {
  
  buttonState = digitalRead(buttonPin); 
  if(buttonState == LOW){
    startTime = millis(); 
  }
  
  while(buttonState == HIGH){
    long time = millis();
    long z = (time - startTime); 
    sec = (z/1000);
    long ms = z%1000; 
    lcd.setCursor(0,1); 
    lcd.print(sec); 
    lcd.print(&quot;.&quot;);
    lcd.print(ms);
    lcd.setCursor(8,1); 
    lcd.print(&quot;Secs&quot;);
    
    if(buttonState == LOW){
      break;   
    }
  }
}

void buttonInterrupt() {
  if(buttonState == LOW){
    buttonState = HIGH; 
  }else{
    buttonState = LOW; 
  }
}

The loop function works as far as time counting is concerned, but doesn't work to stop the time with the button. Any help is appreciated, I'm extremely new to Arduino (literally started yesterday). My circuit looks like this: https://i.imgur.com/yCR9fhP.png
If there is any other way to print the numbers other than printString, more than happy to hear them!
Thanks!
There are several issues here. First and foremost, your button is wired
incorrectly. If you connect one end of the button to +5V, then the other
end should have a pushdown to GND, like here:

(Image from the Arduino Button example).
The second issue is the lack of debouncing. You should ignore the rising
edges you sense for a few milliseconds after you record one.
The third issue is the timekeeping. As explained by Sim Son, your
seconds will not be very accurate. It's better to just count the
milliseconds elapsed since the button press, and then break the count
into full seconds and remaining milliseconds.