I know I'm making a stupid mistake, what is it?

Intended funcationality: I’m making a simple program to draw “buttons” on a LCD. If the switch hasn’t been pressed in 10000ms, the display should sleep. At any time if the display is sleeping and the button is pressed, the display should wake and re-draw.

What really happens:
If the display sleeps and you press the switch immediately, it will wake up. This will repeat until some time has passed (haven’t measured it accurately). After such time, when the screen is in the middle of waking up, it will sleep.

Help!

 int switchPin = 10;
 long lastMillis = 0;
 int thresh = 300;
 
 //sleep information
 int sleepMillis = 10000;
 int lastAction = 0;
 boolean asleep;
 boolean waking = false;

char labels[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
int columns[] = {3, 8, 13, 18, 3, 8, 13, 18};

void setup()
{
  randomSeed(millis());
  Serial.begin(57600);
  Serial.print(186,BYTE);
  delay(1000);
  wakeDisplay();
}

void loop() {
  int read = digitalRead(switchPin);
  
    //input pin is high
  if (read == HIGH) {
    //set the last action to now
    lastAction = millis();
    
    if (asleep) {
      wakeDisplay(); 
    }
    
    /*
    if the debounce indicator is zero and the LCD isn't asleep
    scramble the labels
    add the labels to the display
    set the debounce indicator to now
    */
    if (lastMillis == 0 && !asleep) {
      scramble();
      addLabelsInPosition();
      lastMillis = millis();
    }
    /*
    if now minus the debounce indicator is greater than the threshold,
    reset the debounce indicator
    */
    if ((millis() - lastMillis) > thresh) {
      lastMillis = 0;
    }
  } 
  
  /*
    If the display isn't asleep
    and it's not waking up
    and it's been more than 10000 milliseconds since the last action
    put it to sleep
  */
  if (!asleep && !waking && ((millis() - lastAction) > sleepMillis)) {
    sleepDisplay(); 
  }
  delay(100);
}

void sleepDisplay() {
  //clear the display
  Serial.print(186, BYTE);
  //turn the backlight off
  Serial.print(170, BYTE);
  Serial.print(0, BYTE);
  //allow for switch input to immediately wake the display
  lastMillis = 0;
  asleep = true;
}

void wakeDisplay() {
  waking = true;
  //turn the backlight on
  Serial.print(170, BYTE);
  Serial.print(255, BYTE);
  drawBoxes();
  scramble();
  addLabelsInPosition();
  lastMillis = millis();
  asleep = false;
  lastAction = millis();
  waking = false;
}

void drawBoxes() {
  drawBox(0,0,30,30);
  drawBox(30,0,60,30);
  drawBox(60,0,90,30);
  drawBox(90,0,120,30);
  drawBox(0,30,30,60);
  drawBox(30,30,60,60);
  drawBox(60,30,90,60);
  drawBox(90,30,120,60);
}

void scramble() {
  int i;
  for (i = 0; i < 8; i = i + 1) {
     char original = labels[i];
     
     int foundIndex = int(random(0, 7));
     char found = labels[foundIndex];
     labels[i] = found;
     labels[foundIndex] = original;
  }
}

void addLabelsInPosition() {
  int i;
  for (i = 0; i < 8; i = i + 1) {
     if (i == 0) {
       Serial.print(129, BYTE);
     }
     if (i == 4) {
       Serial.print(132, BYTE);  
     }
     int column = columns[i];
     column = column + 135;
     Serial.print(column, BYTE);
     Serial.print(labels[i]);
     Serial.print(255, BYTE);
     delay(10);
  }
}

void drawBox(int x1, int x2, int y1, int y2) {
  Serial.print(200, BYTE);
  Serial.print(2, BYTE);
  Serial.print(x1, BYTE);
  Serial.print(x2, BYTE);
  Serial.print(y1, BYTE);
  Serial.print(y2, BYTE);
  Serial.print(1, BYTE);
  Serial.print(200, BYTE);
  delay(40);
}

Approximately how much time is passing before the problem occurs?

Could it be caused by millis() rolling back around to 0?

It takes about 50 days for millis() to roll back around to 0.

I figured it out. I was calling millis() and storing it in an int. It overran int and did stupid stuff.

Thanks anyways guys :)

Glad you found it.