Problems with a timer

This is supposed to be a timer for Pomodoro, a time-management technique I like. The only problem is that after one successful cycle, the
program keeps skipping over the timer and cuts straight to the end of the cycle. Any ideas on what’s wrong?

   /**
    PomodoroArduino

    */
    
    #include <LiquidCrystal.h>
    #include "pitches.h"

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    int lastStart = 0;
    int pomodoros = 0;
    const int buttonPin = 7;
    int buttonState = 0;
    boolean completed = true;
    int speakerPin = 8;

    void setup() {
      // set up the LCD's number of columns and rows: 
      lcd.begin(16, 2);
      pinMode(buttonPin, INPUT);
    }

    void backToWorkTone(){
      lcd.setCursor(0, 1);
      lcd.print("BACK TO WORK!!!!");
      int melody[] = {NOTE_FS4, NOTE_C4, NOTE_FS4, NOTE_C4,     NOTE_FS4, NOTE_C4, NOTE_FS4, NOTE_C4};
      // note durations: 4 = quarter note, 8 = eighth note, etc.:
  
      for (int thisNote = 0; thisNote < 8; thisNote++) {
        // to calculate the note duration, take one second 
        // divided by the note type.
        //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
        int noteDuration = 1000/2;
        tone(8, melody[thisNote], noteDuration);

        // to distinguish the notes, set a minimum time between them.
        // the note's duration + 30% seems to work well:
        int pauseBetweenNotes = noteDuration * 1.30;
        delay(pauseBetweenNotes);
        // stop the tone playing:
        noTone(8);
      }
    }

    void victoryTone(){
      int melody[] = {NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4};
      // note durations: 4 = quarter note, 8 = eighth note, etc.:
      int noteDurations[] = {4, 8, 8, 4,4,4,4,4 };
      for (int thisNote = 0; thisNote < 8; thisNote++) {
        // to calculate the note duration, take one second 
        // divided by the note type.
        //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
        int noteDuration = 1000/noteDurations[thisNote];
        tone(8, melody[thisNote],noteDuration);
        // to distinguish the notes, set a minimum time between them.
        // the note's duration + 30% seems to work well:
        int pauseBetweenNotes = noteDuration * 1.30;
        delay(pauseBetweenNotes);
        // stop the tone playing:
        noTone(8);
      }
    }

    void loop() {
      lcd.print("Pomodoros: " + (String)pomodoros);
      lcd.setCursor(0, 1);
      lcd.print("Ready to start? ");
      if(digitalRead(buttonPin) == HIGH){
        newPomodoro();
      }
    }

    int getSeconds(int lastStart){
      return (millis() - lastStart)/1000;
    }

    String timeToString(int seconds){
      int secondsToPrint = seconds%60;
      int minutesToPrint = seconds / 60;
      String toBeOutput = "";
      if(minutesToPrint < 10){
        toBeOutput += "0";
      }
      toBeOutput += minutesToPrint;
      toBeOutput += ":";
      if(secondsToPrint < 10){
        toBeOutput += "0";
      }
      toBeOutput += secondsToPrint;
      return toBeOutput;
    }

    void workCycle(){
      delay(1000);
      while(getSeconds(lastStart) <  20){ //CHANGE BACK TO 25
        lcd.setCursor(0, 1);
        lcd.print("Elapsed: " + timeToString(getSeconds(lastStart)));
   
        if(digitalRead(buttonPin) == HIGH){
          completed = false;
          break;
        } 
      }
      if(completed)
        victoryTone();
    }
  
    void newPomodoro(){
      completed = true;
      lastStart = millis();
      lcd.clear();
      lcd.print("Pomodoros: " + (String)pomodoros);
      workCycle();
      if(completed){
        pomodoros++;
        lcd.clear();
        breakMenuLoop();
      }
      delay(1000);
      loop();
    }

    void breakMenuLoop(){
      delay(1000);
      boolean waiterBoolean = true;
      while(waiterBoolean){
        lcd.print("Pomodoros: " + (String)pomodoros);
        lcd.setCursor(0, 1);
        lcd.print("Ready for break?");
        if(digitalRead(buttonPin) == HIGH)
          waiterBoolean = false;
        }
      lastStart = millis();
      breakCycle();
    }

    void breakCycle(){ //cycle for when on break; not for breaking any cycle
      delay(1000);
      while(getSeconds(lastStart) < 10){ //CHANGE BACK TO 5
        lcd.setCursor(0, 1);
        lcd.print("On break!  " + timeToString(getSeconds(lastStart)));
        if(digitalRead(buttonPin) == HIGH){
          completed = false;
          break;
        } 
      }
      backToWorkTone();
    }

I can see a bit problem here:

    int getSeconds(int lastStart){
      return (millis() - lastStart)/1000;
    }

millis() returns an unsigned long int. Those ints are not big enough.

    int lastStart = 0;
      lastStart = millis();

And another place where failing to read the reference material is taking a bite out of your ass.

TanHadron: I can see a bit problem here:

    int getSeconds(int lastStart){
      return (millis() - lastStart)/1000;
    }

millis() returns an unsigned long int. Those ints are not big enough.

I see.

PaulS:     int lastStart = 0;       lastStart = millis();

And another place where failing to read the reference material is taking a bite out of your ass.

What's wrong here, though?

What's wrong here, though?

After the Arduino has been running for 32.767 seconds, millis() returns values that cause an int to overflow, resulting in negative values. Time runs backwards only in weird movies like Back To The Future.

PaulS:

What's wrong here, though?

After the Arduino has been running for 32.767 seconds, millis() returns values that cause an int to overflow, resulting in negative values. Time runs backwards only in weird movies like Back To The Future.

Or Dr. Who. Can't for get Dr. Who. :P

Or Dr. Who. Can't for get Dr. Who.

Dr. Who? Never watched it.

There was a question on a white board at working, mentioning the end of the 38th season of Saturday Night Live, asking about people's favorite episode. Beats me. Never seen that show, either.

Wow, that fixes everything! That was surprisingly simple. Thank you all so much!