LCD corruption

I’m having some trouble with my LCD’s text becoming corrupted. it only seems to happen when I press a button wired to digital pin 9 repeatedly. below is the only section of my code that changes the LCD in any way. pressing the button flips the ‘light’ var true/false

Here’s what I mean by ‘becoming corrupted’:

 if(timers[3] < timers[1]){                                     //refresh screen on timer
    timers[3] = timers[1] + scrRefresh;  //scrRefresh = 1000 timers[1] = millis()

    lcd.clear();                                        //update temp info (line 1)
    lcd.setCursor(3, 0);
    lcd.print(temp); //int
    lcd.print("c");
    lcd.setCursor(9, 0);
    lcd.print(on); //byte
    lcd.print("-");
    lcd.print(off); //byte
    
    

    
    if(!pause){                                                //update line 2
      lcd.setCursor(0, 1);
      lcd.print("State:          ");
      lcd.setCursor(7, 1);
      if(state) lcd.print("On");
      else lcd.print("Off");
    }
    else{
      lcd.setCursor(0, 1);
      lcd.print("Paused:         ");
      if((timers[2] - timers[1]) > 60000){                         // paused and pause timer greater than 1min?
        int minutes = (timers[2] - timers[1]) / 1000 / 60;
        int seconds = ((timers[2] - timers[1]) / 1000) - minutes * 60;
        lcd.setCursor(8, 1);
        lcd.print(minutes);
        lcd.print("m");
        lcd.print(seconds);
        lcd.print("s");
      }
      else{
        lcd.setCursor(8, 1);
        lcd.print(int((timers[2] - timers[1]) / 1000));
        lcd.print("s");
      }
    }
    
    lcd.setCursor(15,1);
    if(light) lcd.print(".");                                 //light indicator
  }

You can find the full code Here

Alright, after much screwing about. The problem seems to have been a power supply issue. the arduino 5V regulator cannot supply enough current to trigger my relay board as well as run the LCD reliably. switching the relay boards vcc from the 5v pin to Vin (5v from usb) has fixed it.

. . . below is the only section of my code that changes the LCD in any way. . . .

Except for the section of your code that triggers the relays that change the LCD in a way that you didn't expect but that we have seen over and over again.

You got lucky this time and stumbled upon one of the solutions to your problem. In general you will get the most relevant help if you post all of your code and also post a photograph that shows everything that is connected to your Arduino.

Don

floresta:
Except for the section of your code that triggers the relays that change the LCD in a way that you didn’t expect but that we have seen over and over again.

post all of your code and also post a photograph that shows everything that is connected to your Arduino.

the section of code I posted includes every lcd. in my code. it seemed the most relevant so I added it to my post. The rest of my code can be found in the pastebin link in the first comment because of the character limit on this forum. As for a photo, there isn’t much too see, its in a small box with a bit of a mess of wiring. But should someone have requested a pic, or a wiring schematic, that could be arranged.

As a general rule, we expect to see your code in one piece in a "code" box, the whole code and nothing but your code.

And a photo showing your whole setup, without any parts obscured by stray wiring, taken in full daylight (but not sun) with a proper camera using zoom from at least a metre away so that it is perfectly illuminated and focussed.