Stopping a countdown timer when it hits 0 I am trying to modify the following sketch to count down (which seems to be partially working).  What do I need to modify, to get the timer to stop at zero? Right now it counts down from 10 seconds, goes past zero and into the negatives.  I really struggle with coding, I've tried studying other peoples sketches, researching on-line, purchased (and studied) a couple Simon Monks books, but I'm still unable to work through this.  Can someone please point me in the right direction?  

#include &lt;Adafruit_GFX.h&gt;
#include &lt;Adafruit_SSD1306.h&gt;

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define WAITING 0 // waiting to start
#define TIMERONE 1 // timer one running
#define FINISHED 3 // timer complete
#define countdown 10
const int resetPin = 6;
const int buttonPin = 7;
const int ledPin =  13;      // the number of the LED pin

long startTime = 0;
long timeOne = 0;
int timer = WAITING; // timer state. Initially waiting for first button press
int reset = 0;  // reset button state
int button = 0; // main button state

void setup()   {

  pinMode(buttonPin, INPUT); //init button pin to input
  pinMode(resetPin, INPUT);  //init reset pin to input
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3c
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(55, 00);
  printDigits(0);
}

void loop() {
  //-------- main loop -------
  switch (timer) {
    case WAITING: // initial state - waiting for first button press.
      display.clearDisplay();
      display.setCursor(55, 00);
      printDigits(0);
      display.display(); // display screen showing 00:00
      button = digitalRead(buttonPin);
      if (button) { // button is pressed.
        timer = TIMERONE;
        startTime = millis();//read the time the button is pressed.
        while (digitalRead(buttonPin)) {
          //--- wait for button to be released.
        }
      }
      break;
    case TIMERONE:
      timeOne = millis();
      button = digitalRead(buttonPin);
      reset = digitalRead(resetPin);
      display.clearDisplay();
      display.setCursor(55, 00);
      printDigits (timeOne - startTime);
      display.display();
      //-----------------------------------
      if (reset) { //reset button was pressed. Clear screeen and start again
        timer = WAITING;
        while (digitalRead(resetPin)) {
          //--- wait for reset button to be released.
        }
      }
      if (button) { // button was pressed
        timer = FINISHED;
        while (digitalRead(buttonPin)) {
          //--- wait for button to be released.
        }
      }
      break;
    case FINISHED:
      reset = digitalRead(resetPin);
      if (reset) { //reset button was pressed. Clear screeen and start again
        display.clearDisplay();
        display.setCursor(55, 0);
        printDigits(0);
        display.display();
        timer = WAITING;
        while (digitalRead(resetPin)) {
        }
      }
      break;
  }
}

void printDigits(long timeInMillis) {
  int seconds;
  int hundredths;

  seconds = countdown - timeInMillis / 1000;
  hundredths = (timeInMillis % 1000) / 10;

  if (seconds &lt; 10) { // print leading zero if necessary
    display.print("0");
  }
  display.print(seconds);
  display.print(":");
  if (hundredths &lt; 10) { //print leading zero if necessary
    display.print("0");

  }
  display.print(hundredths);

}
In this line you are calculating the time you are going to display.   You could use that same calculation in an if statement to put you into the FINISHED state in your state machine.  

printDigits (timeOne - startTime);
if(timeOne - startTime &gt;= someInterval) {
    timer = FINISHED;
}


where someInterval is the number of milliseconds you want the timer to run for.