SOLVED Menu screens with touch LCD screen-only working once

Hi,

I am new to everything coding and arduino and have taught myself everything I know so far from online tutorials so my code may not be entirely efficient, but hopefully understandable-although any tips would be appreciated.

I am trying to make a menu with an LCD touchscreen with a settings button to take the user to a settings screen. On the settings screen there is a back button to the main menu. I have not activated any other buttons at this stage to keep it more simple as I build my code. Upon uploading the sketch the settings button takes the user to the settings menu as required, the back button then takes the user back to the main menu. However this only happens once. The settings button while it is highlighting as though it is selected does not take the user back to the settings screen for a second time, only initially after sketch upload.

I have included my code, the parts to make the screens I haven't commented yet or tidied so there may be some redundancies there that I haven't fixed yet.

Thanks in advance

int currentPage;
int pressedButton;
int Settings;
int Back;

void setup() {
  // put your setup code here, to run once:
myGLCD.InitLCD();
myGLCD.clrScr();


myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
  
sensors.begin();
rtc.begin();

mainScreen();
currentPage=0;



}

void loop() {
  // put your main code here, to run repeatedly:

if(myTouch.dataAvailable()==true){        //check if touch screen has been touched
  pressedButton=myButtons.checkButtons();   //which button pressed?
  if(currentPage==0){                         //if currently on main menu (page 0)
    if(pressedButton==Settings){              //if the button selected is Settings
      myGLCD.clrScr();                        //clear LCD Screen
      settingsScreen();                       //Write the settings screen
      currentPage=1;                          //Change current screen to settings screen (Page 1)
    }
  }
   if(currentPage==1){                         //if currently on settings menu (page 1)
   if(pressedButton==Back){                    //if the button selected is Back
      myGLCD.clrScr();                         //clear LCD Screen
      mainScreen();                            //Write the main screen
      currentPage=0;                           //Change current screen to settings screen (Page 0)
    }
  }
}

}


void mainScreen(){
  
String DOW;
String Date;
String t;


DOW=rtc.getDOWStr(FORMAT_LONG);
Date=rtc.getDateStr(FORMAT_SHORT);
t=rtc.getTimeStr(FORMAT_SHORT);

float temp;
sensors.requestTemperatures();
temp=sensors.getTempCByIndex(0);

myGLCD.setBackColor(VGA_SILVER);
myGLCD.setColor(VGA_NAVY);
myGLCD.fillScr(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.print(DOW,10,10);
myGLCD.setFont(Grotesk16x32);
myGLCD.print(Date,10,40);
myGLCD.print(t,10,70);

myGLCD.setFont(Grotesk16x32);
myGLCD.print("6.6",215,10);
myGLCD.print("38%",215,65);
myGLCD.printNumF(temp,1,215,125);
myGLCD.print("2.2",215,180);

myGLCD.setFont(SmallFont);
myGLCD.print("pH",170,10);
myGLCD.print("CO2",170,65);
myGLCD.print("temp",170,125);
myGLCD.print("flow",170,180);


myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
setBut=myButtons.addButton(10,150,140,70,"Settings");
myButtons.drawButton(setBut);


}

void settingsScreen(){

myGLCD.fillScr(VGA_SILVER);
myGLCD.setBackColor(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.setColor(VGA_NAVY);
myGLCD.print("Settings",20,10);



myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
setBackBut=myButtons.addButton(220,10,80,40,"Back");
setLightBut=myButtons.addButton(20,80,130,60,"Lights");
setCo2But=myButtons.addButton(20,160,130,60,"CO2");
setDosingBut=myButtons.addButton(170,80,130,60,"Dosing");
setOutletBut=myButtons.addButton(170,160,130,60,"Outlet");
myButtons.drawButton(setBackBut);
}

You don't assign values to Back and Settings so they're the same thing. Some weirdness may happen because you've chained the if statements such that when the main menu switches to settings, the next if is immediately run (because currentpage is now 1) etc.

Consider using a state machine for you menu system. It can help reduce error-inducing nesting of if/else statements, makes adding features later easuer and makes the code generally cleaner over all.

Do this behave more as you expect?

int currentPage;
int pressedButton;

const int Settings = x; //SHOULD ASSIGN SOMETHING TO THESE
const int Back = y;     

void setup() 
{
    // put your setup code here, to run once:
    myGLCD.InitLCD();
    myGLCD.clrScr();
    
    myTouch.InitTouch();
    myTouch.setPrecision(PREC_MEDIUM);
  
    sensors.begin();
    rtc.begin();

    mainScreen();
    currentPage=0;
}

void MenuStateMachine( int button )
{
    switch( currentPage )
    {
        case    0:
            if( button == Settings )
            {
                myGLCD.clrScr();                        //clear LCD Screen
                settingsScreen();                       //Write the settings screen
                currentPage=1;                          //Change current screen to settings screen (Page 1)               
                
            }//if
            
        break;

        case    1:
            if( button == Back )
            {                    
                //if the button selected is Back
                myGLCD.clrScr();                         //clear LCD Screen
                mainScreen();                            //Write the main screen
                currentPage=0;                           //Change current screen to settings screen (Page 0)
                
            }//if
            
        break;
        
    }//switch
    
}//MenuStateMachine

void loop() 
{
    // put your main code here, to run repeatedly:

    if(myTouch.dataAvailable() == true)
        MenuStateMachine( myButtons.checkButtons() );

}//loop


void mainScreen()
{
  
    String DOW;
    String Date;
    String t;

    DOW=rtc.getDOWStr(FORMAT_LONG);
    Date=rtc.getDateStr(FORMAT_SHORT);
    t=rtc.getTimeStr(FORMAT_SHORT);

    float temp;
    sensors.requestTemperatures();
    temp=sensors.getTempCByIndex(0);

    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setFont(GroteskBold16x32);
    myGLCD.print(DOW,10,10);
    myGLCD.setFont(Grotesk16x32);
    myGLCD.print(Date,10,40);
    myGLCD.print(t,10,70);

    myGLCD.setFont(Grotesk16x32);
    myGLCD.print("6.6",215,10);
    myGLCD.print("38%",215,65);
    myGLCD.printNumF(temp,1,215,125);
    myGLCD.print("2.2",215,180);

    myGLCD.setFont(SmallFont);
    myGLCD.print("pH",170,10);
    myGLCD.print("CO2",170,65);
    myGLCD.print("temp",170,125);
    myGLCD.print("flow",170,180);

    myButtons.setTextFont(Grotesk16x32);
    myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
    setBut=myButtons.addButton(10,150,140,70,"Settings");
    myButtons.drawButton(setBut);

}

void settingsScreen()
{

    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setFont(GroteskBold16x32);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.print("Settings",20,10);

    myButtons.setTextFont(Grotesk16x32);
    myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
    setBackBut=myButtons.addButton(220,10,80,40,"Back");
    setLightBut=myButtons.addButton(20,80,130,60,"Lights");
    setCo2But=myButtons.addButton(20,160,130,60,"CO2");
    setDosingBut=myButtons.addButton(170,80,130,60,"Dosing");
    setOutletBut=myButtons.addButton(170,160,130,60,"Outlet");
    myButtons.drawButton(setBackBut);

Thank you for your reply. I had tried a switch before and it didn't work, although i like how you comment for each close of the curly brackets to keep track of them- I will do this in the future. One mistake that I had in the code is inconsistencies with the names of those variables as I changed the names for ease of use in the forum. The UFT Buttons library assigns an integer to those values when it creates a button is my understanding. However I also tried giving these values as you suggested and it had the same outcome. Now though the menu is stuck on the settings menu and won't return to the main menu.

int setLightBut;
int setCo2But;
int setDosingBut;
int setOutletBut;


int currentPage;
int pressedButton;
int Settings=1;
int Back=2;

void setup() {
  // put your setup code here, to run once:
myGLCD.InitLCD();
myGLCD.clrScr();


myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
  
sensors.begin();
rtc.begin();

mainScreen();
currentPage=0;



}

void MenuStateMachine( int button )
{
    switch( currentPage )
    {
        case    0:
            if( pressedButton == Settings )
            {
                myGLCD.clrScr();                        //clear LCD Screen
                settingsScreen();                       //Write the settings screen
                currentPage=1;                          //Change current screen to settings screen (Page 1)               
                
            }//if
            
        break;

        case    1:
            if( pressedButton == Back )
            {                    
                //if the button selected is Back
                myGLCD.clrScr();                         //clear LCD Screen
                mainScreen();                            //Write the main screen
                currentPage=0;                           //Change current screen to settings screen (Page 0)
                
            }//if
            
        break;
        
    }//switch
    
}//MenuStateMachine

void loop() 
{
    // put your main code here, to run repeatedly:

    if(myTouch.dataAvailable() == true)
        MenuStateMachine( myButtons.checkButtons() );

}//loop


void mainScreen(){
  
String DOW;
String Date;
String t;


DOW=rtc.getDOWStr(FORMAT_LONG);
Date=rtc.getDateStr(FORMAT_SHORT);
t=rtc.getTimeStr(FORMAT_SHORT);

float temp;
sensors.requestTemperatures();
temp=sensors.getTempCByIndex(0);

myGLCD.setBackColor(VGA_SILVER);
myGLCD.setColor(VGA_NAVY);
myGLCD.fillScr(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.print(DOW,10,10);
myGLCD.setFont(Grotesk16x32);
myGLCD.print(Date,10,40);
myGLCD.print(t,10,70);

myGLCD.setFont(Grotesk16x32);
myGLCD.print("6.6",215,10);
myGLCD.print("38%",215,65);
myGLCD.printNumF(temp,1,215,125);
myGLCD.print("2.2",215,180);

myGLCD.setFont(SmallFont);
myGLCD.print("pH",170,10);
myGLCD.print("CO2",170,65);
myGLCD.print("temp",170,125);
myGLCD.print("flow",170,180);


myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
[b]Settings=myButtons.addButton(10,150,140,70,"Settings");[/b]
myButtons.drawButton(Settings);


}

void settingsScreen(){

myGLCD.fillScr(VGA_SILVER);
myGLCD.setBackColor(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.setColor(VGA_NAVY);
myGLCD.print("Settings",20,10);



myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
[b]Back=myButtons.addButton(220,10,80,40,"Back");[/b]
setLightBut=myButtons.addButton(20,80,130,60,"Lights");
setCo2But=myButtons.addButton(20,160,130,60,"CO2");
setDosingBut=myButtons.addButton(170,80,130,60,"Dosing");
setOutletBut=myButtons.addButton(170,160,130,60,"Outlet");
myButtons.drawButton(Back);
myButtons.drawButton(setLightBut);
myButtons.drawButton(setDosingBut);
myButtons.drawButton(setCo2But);
myButtons.drawButton(setOutletBut);


}

Ah, okay. I see there where the value of Settings and Back are created.

Which touch library are you using? It seems like there's some stuff (e.g. includes) missing from your listing.

You call 'MenuStateMachine' by passing the pressed button as parameter.

  if (myTouch.dataAvailable() == true)
    MenuStateMachine( myButtons.checkButtons() );

In 'MenuStateMachine' you test 'pressedButton' (which is unassigned) in stead of 'button' wich is passed over....

void MenuStateMachine( int button )
{
  switch ( currentPage )
  {
    case    0:
      if ( pressedButton == Settings )
      {

leongjerland:
You call 'MenuStateMachine' by passing the pressed button as parameter.

  if (myTouch.dataAvailable() == true)

MenuStateMachine( myButtons.checkButtons() );




In 'MenuStateMachine' you test 'pressedButton' (which is unassigned) in stead of 'button' wich is passed over....


void MenuStateMachine( int button )
{
  switch ( currentPage )
  {
    case    0:
      if ( pressedButton == Settings )
      {

Damn. Good catch. Fixed...

Here is the entire code. I don’t quite understand the correction that was made by leongjerland just there, if someone could explain please. This has all the libraries in there now, sorry I didn’t include them properly before. There are parts to the code that are not being used and some constants remaining from where I have tried different methods to get the buttons to work in the first place that I haven’t cleaned up yet.

#include <URTouch.h>
#include <UTFT_Buttons.h>
#include <memorysaver.h>
#include <UTFT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS3231.h>


extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
extern uint8_t GroteskBold24x48[];
extern uint8_t CalibriBold32x48[];
extern uint8_t GroteskBold16x32[];
extern uint8_t Grotesk16x32[];

UTFT myGLCD(ILI9341_16,38,39,40,41);

//Temp
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


//RTC
DS3231 rtc(SDA,SCL);

//Touch Screen
URTouch myTouch(6,5,4,3,2);

UTFT_Buttons myButtons(&myGLCD,&myTouch);


int x;
int y;



int setLightBut;
int setCo2But;
int setDosingBut;
int setOutletBut;


int currentPage;
int pressedButton;
int Settings=1;
int Back=2;

void setup() {
  // put your setup code here, to run once:
myGLCD.InitLCD();
myGLCD.clrScr();


myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
  
sensors.begin();
rtc.begin();

mainScreen();
currentPage=0;



}

void MenuStateMachine( int pressedButton )
{
    switch( currentPage )
    {
        case    0:
            if( pressedButton == Settings )
            {
                myGLCD.clrScr();                        //clear LCD Screen
                settingsScreen();                       //Write the settings screen
                currentPage=1;                          //Change current screen to settings screen (Page 1)               
                
            }//if
            
        break;

        case    1:
            if( pressedButton == Back )
            {                    
                //if the button selected is Back
                myGLCD.clrScr();                         //clear LCD Screen
                mainScreen();                            //Write the main screen
                currentPage=0;                           //Change current screen to settings screen (Page 0)
                
            }//if
            
        break;
        
    }//switch
    
}//MenuStateMachine

void loop() 
{
    // put your main code here, to run repeatedly:

    if(myTouch.dataAvailable() == true)
        MenuStateMachine( myButtons.checkButtons() );

}//loop


void mainScreen(){
  
String DOW;
String Date;
String t;


DOW=rtc.getDOWStr(FORMAT_LONG);
Date=rtc.getDateStr(FORMAT_SHORT);
t=rtc.getTimeStr(FORMAT_SHORT);

float temp;
sensors.requestTemperatures();
temp=sensors.getTempCByIndex(0);

myGLCD.setBackColor(VGA_SILVER);
myGLCD.setColor(VGA_NAVY);
myGLCD.fillScr(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.print(DOW,10,10);
myGLCD.setFont(Grotesk16x32);
myGLCD.print(Date,10,40);
myGLCD.print(t,10,70);

myGLCD.setFont(Grotesk16x32);
myGLCD.print("6.6",215,10);
myGLCD.print("38%",215,65);
myGLCD.printNumF(temp,1,215,125);
myGLCD.print("2.2",215,180);

myGLCD.setFont(SmallFont);
myGLCD.print("pH",170,10);
myGLCD.print("CO2",170,65);
myGLCD.print("temp",170,125);
myGLCD.print("flow",170,180);


myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
Settings=myButtons.addButton(10,150,140,70,"Settings");
myButtons.drawButton(Settings);


}

void settingsScreen(){

myGLCD.fillScr(VGA_SILVER);
myGLCD.setBackColor(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.setColor(VGA_NAVY);
myGLCD.print("Settings",20,10);



myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
Back=myButtons.addButton(220,10,80,40,"Back");
setLightBut=myButtons.addButton(20,80,130,60,"Lights");
setCo2But=myButtons.addButton(20,160,130,60,"CO2");
setDosingBut=myButtons.addButton(170,80,130,60,"Dosing");
setOutletBut=myButtons.addButton(170,160,130,60,"Outlet");
myButtons.drawButton(Back);
myButtons.drawButton(setLightBut);
myButtons.drawButton(setDosingBut);
myButtons.drawButton(setCo2But);
myButtons.drawButton(setOutletBut);


}

void lightScreen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("LIGHTS",CENTER,100);
}

void co2Screen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("CO2",CENTER,100);
}

void dosingScreen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("Dosing",CENTER,100);
}

void outletScreen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("Outlets",CENTER,100);
}

I have worked out now what leongjerland corrected in the first instance, so don’t worry about answering that question now.

I can’t work out why this isn’t working. I have gone through the entire code to find the issue. Here is the new version with more notes so it is clearer.

My understanding of the switch is as follows:

MenuStateMachine( myButtons.checkButtons() ); //calls the state machine and assigns the variable pressedButton (the integer variable assigned in the bracket when defining the function) as the checkButton

switch (currentPage) // analyses the currentPage variable to check against the cases (set as 0 in void setup- main screen)

Case 0: //when currentPage=0 (MainScreen) runs the code following

if( pressedButton == MainSettings ) // so if the button was the settings button code continues
myGLCD.clrScr();
settingsScreen();
currentPage=1; //clears screen, writes settings screen, changes current page variable to 1

break;

case 1: //when currentPage=1 (settings screen) runs code

if( pressedButton == SettingsBack ) // if the button pressed was the back button runs code
myGLCD.clrScr();
mainScreen();
currentPage=0; //clears screen, writes menu screen, changes current page to 0

break;

so I don’t understand why the settings button doesn’t work when I return to the home screen, because the last line in the case 1 is returning current page to 0 therefore should work with case 0 again. I have no idea where I have gone wrong. Everything works when the code has been uploaded just not once it’s gone through everything once.

currently this is what happens

code uploaded>>>
Main screen shows
selects Settings button
Setting Screen shows
selects Back Button
Main Screen Shows
selects Settings button
stays on main screen-

the button has a red border when selected so I know it is recognising the touch but it is doing nothing with it

#include <URTouch.h>
#include <UTFT_Buttons.h>
#include <memorysaver.h>
#include <UTFT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS3231.h>


extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
extern uint8_t GroteskBold24x48[];
extern uint8_t CalibriBold32x48[];
extern uint8_t GroteskBold16x32[];
extern uint8_t Grotesk16x32[];

UTFT myGLCD(ILI9341_16,38,39,40,41);

//Temp
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


//RTC
DS3231 rtc(SDA,SCL);

//Touch Screen
URTouch myTouch(6,5,4,3,2);

UTFT_Buttons myButtons(&myGLCD,&myTouch);

//Buttons on Setting Screen

int SettingsLight;            //Button on Settings screen for light
int SettingsCO2;              //Button on Settings screen for CO2
int SettingsDosing;           //Button on Settings screen for Dosing
int SettingsOutlet;           //Button on Settings screen for Outlet
int SettingsBack;             //Button on Settings screen to go back to home screen

//Buttons on Main Screen

int MainSettings;             //Button on Main Screen for Settings


//variables for progressing page

int currentPage;


//Screen Numbers
//Main Screen = 0
//Settings Screen = 1



void setup() {
  // put your setup code here, to run once:
myGLCD.InitLCD();                           //initialising LCD
myGLCD.clrScr();


myTouch.InitTouch();                        //initialising Touch
myTouch.setPrecision(PREC_MEDIUM);
  
sensors.begin();                            //Starting Temp Sensor
rtc.begin();                                //Starting RTC

mainScreen();                               //Draw Home Screen
currentPage=0;                              //Set Current Page to 0 (main Screen)



}


void loop() 
{
    // put your main code here, to run repeatedly:

    if(myTouch.dataAvailable() == true)
        MenuStateMachine( myButtons.checkButtons() );

}//loop

void MenuStateMachine( int pressedButton )
{
    switch( currentPage )
    {
        case    0:
            if( pressedButton == MainSettings )
            {
                myGLCD.clrScr();                        //clear LCD Screen
                settingsScreen();                       //Write the settings screen
                currentPage=1;                          //Change current screen to settings screen (Page 1)               
                
            }//if
            
        break;

        case    1:
            if( pressedButton == SettingsBack )
            {                    
                //if the button selected is Back
                myGLCD.clrScr();                         //clear LCD Screen
                mainScreen();                            //Write the main screen
                currentPage=0;                           //Change current screen to settings screen (Page 0)
                
            }//if
            
        break;
        
    }//switch
    
}//MenuStateMachine

//Drawing Screens
//Main Screen

void mainScreen(){
  
String DOW;                       //set variable for Day Of Week
String Date;                      //set variable for Date
String t;                         //set variable for Time
float temp;                       //set variable for Temperature

//collecting info from RTC

DOW=rtc.getDOWStr(FORMAT_LONG);         //info for DOW
Date=rtc.getDateStr(FORMAT_SHORT);      //info for Date
t=rtc.getTimeStr(FORMAT_SHORT);         //info for Time

//collecting info from temp sensor

sensors.requestTemperatures();          //get info from sensor
temp=sensors.getTempCByIndex(0);        //put temp info into variable

//set background and Date/time info

myGLCD.setBackColor(VGA_SILVER);
myGLCD.setColor(VGA_NAVY);
myGLCD.fillScr(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.print(DOW,10,10);
myGLCD.setFont(Grotesk16x32);
myGLCD.print(Date,10,40);
myGLCD.print(t,10,70);

//print data ph/Co2/temp/flow

myGLCD.setFont(Grotesk16x32);
myGLCD.print("6.6",215,10);
myGLCD.print("38%",215,65);
myGLCD.printNumF(temp,1,215,125);
myGLCD.print("2.2",215,180);

myGLCD.setFont(SmallFont);
myGLCD.print("pH",170,10);
myGLCD.print("CO2",170,65);
myGLCD.print("temp",170,125);
myGLCD.print("flow",170,180);

//create settings button

myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
MainSettings=myButtons.addButton(10,150,140,70,"Settings");
myButtons.drawButton(MainSettings);


}

//Draw Settings Screen

void settingsScreen(){

//Background and Title  

myGLCD.fillScr(VGA_SILVER);
myGLCD.setBackColor(VGA_SILVER);
myGLCD.setFont(GroteskBold16x32);
myGLCD.setColor(VGA_NAVY);
myGLCD.print("Settings",20,10);

//Drawing Buttons

myButtons.setTextFont(Grotesk16x32);
myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
SettingsBack=myButtons.addButton(220,10,80,40,"Back");
SettingsLight=myButtons.addButton(20,80,130,60,"Lights");
SettingsCO2=myButtons.addButton(20,160,130,60,"CO2");
SettingsDosing=myButtons.addButton(170,80,130,60,"Dosing");
SettingsOutlet=myButtons.addButton(170,160,130,60,"Outlet");
myButtons.drawButton(SettingsBack);
myButtons.drawButton(SettingsLight);
myButtons.drawButton(SettingsDosing);
myButtons.drawButton(SettingsCO2);
myButtons.drawButton(SettingsOutlet);


}

void lightScreen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("LIGHTS",CENTER,100);
}

void co2Screen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("CO2",CENTER,100);
}

void dosingScreen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("Dosing",CENTER,100);
}

void outletScreen(){
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_SILVER);
  myGLCD.setBackColor(VGA_SILVER);
  myGLCD.setFont(GroteskBold24x48);
  myGLCD.setColor(VGA_NAVY);
  myGLCD.print("Outlets",CENTER,100);
}

Each time you run mainScreen() and settingsScreen() you create a new button (MainSettings and SettingsBack). I get the feeling that when a screen is destroyed (e.g. main, moving from main to settings) that all buttons should be deleted and new ones created. You already create new ones; how about adding destruction calls like

#include <URTouch.h>
#include <UTFT_Buttons.h>
#include <memorysaver.h>
#include <UTFT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS3231.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
extern uint8_t GroteskBold24x48[];
extern uint8_t CalibriBold32x48[];
extern uint8_t GroteskBold16x32[];
extern uint8_t Grotesk16x32[];

UTFT myGLCD(ILI9341_16,38,39,40,41);

//Temp
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


//RTC
DS3231 rtc(SDA,SCL);

//Touch Screen
URTouch myTouch(6,5,4,3,2);

UTFT_Buttons myButtons(&myGLCD,&myTouch);

//Buttons on Setting Screen

int SettingsLight;            //Button on Settings screen for light
int SettingsCO2;              //Button on Settings screen for CO2
int SettingsDosing;           //Button on Settings screen for Dosing
int SettingsOutlet;           //Button on Settings screen for Outlet
int SettingsBack;             //Button on Settings screen to go back to home screen

//Buttons on Main Screen

int MainSettings;             //Button on Main Screen for Settings

//variables for progressing page

//Screen Numbers
//Main Screen = 0
//Settings Screen = 1
#define SCRN_MAIN           0
#define SCRN_SETTINGS       1

int currentPage;

void setup() 
{
  // put your setup code here, to run once:
    myGLCD.InitLCD();                           //initialising LCD
    myGLCD.clrScr();
    myTouch.InitTouch();                        //initialising Touch
    myTouch.setPrecision(PREC_MEDIUM);
  
    sensors.begin();                            //Starting Temp Sensor
    rtc.begin();                                //Starting RTC

    mainScreen();                               //Draw Home Screen
    currentPage=SCRN_MAIN;                      //Set Current Page to 0 (main Screen)
    
}//setup

void loop() 
{
    // put your main code here, to run repeatedly:
    MenuStateMachine( myButtons.checkButtons() );

}//loop

void MenuStateMachine( int Btn )
{
    //checkButtons returns -1 if there's no button press available
    if( Btn == -1 )
        return;
        
    switch( currentPage )
    {
        case    SCRN_MAIN:
            if( Btn == MainSettings )
            {
                myGLCD.clrScr();                        //clear LCD Screen
                myButtons.deleteAllButtons();           //clear all existing buttons
                settingsScreen();                       //Write the settings screen
                currentPage = SCRN_SETTINGS;            //Change current screen to settings screen (Page 1)               
                
            }//if
            
        break;

        case    SCRN_SETTINGS:
            if( Btn == SettingsBack )
            {                    
                //if the button selected is Back
                myGLCD.clrScr();                         //clear LCD Screen
                myButtons.deleteAllButtons();            //clear all existing buttons
                mainScreen();                            //Write the main screen
                currentPage = SCRN_MAIN;                 //Change current screen to settings screen (Page 0)
                
            }//if
            
        break;
        
    }//switch
    
}//MenuStateMachine

//Drawing Screens
//Main Screen

void mainScreen()
{  
    String DOW;                       //set variable for Day Of Week
    String Date;                      //set variable for Date
    String t;                         //set variable for Time
    float temp;                       //set variable for Temperature

    //collecting info from RTC

    DOW=rtc.getDOWStr(FORMAT_LONG);         //info for DOW
    Date=rtc.getDateStr(FORMAT_SHORT);      //info for Date
    t=rtc.getTimeStr(FORMAT_SHORT);         //info for Time

    //collecting info from temp sensor

    sensors.requestTemperatures();          //get info from sensor
    temp=sensors.getTempCByIndex(0);        //put temp info into variable

    //set background and Date/time info

    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setFont(GroteskBold16x32);
    myGLCD.print(DOW,10,10);
    myGLCD.setFont(Grotesk16x32);
    myGLCD.print(Date,10,40);
    myGLCD.print(t,10,70);

    //print data ph/Co2/temp/flow

    myGLCD.setFont(Grotesk16x32);
    myGLCD.print("6.6",215,10);
    myGLCD.print("38%",215,65);
    myGLCD.printNumF(temp,1,215,125);
    myGLCD.print("2.2",215,180);

    myGLCD.setFont(SmallFont);
    myGLCD.print("pH",170,10);
    myGLCD.print("CO2",170,65);
    myGLCD.print("temp",170,125);
    myGLCD.print("flow",170,180);

    //create settings button

    myButtons.setTextFont(Grotesk16x32);
    myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
    MainSettings=myButtons.addButton(10,150,140,70,"Settings");
    myButtons.drawButton(MainSettings);

}//mainScreen

//Draw Settings Screen

void settingsScreen()
{
    //Background and Title  

    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setFont(GroteskBold16x32);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.print("Settings",20,10);

    //Drawing Buttons

    myButtons.setTextFont(Grotesk16x32);
    myButtons.setButtonColors(VGA_NAVY,VGA_WHITE,VGA_NAVY,VGA_RED,VGA_GRAY);
    SettingsBack=myButtons.addButton(220,10,80,40,"Back");
    SettingsLight=myButtons.addButton(20,80,130,60,"Lights");
    SettingsCO2=myButtons.addButton(20,160,130,60,"CO2");
    SettingsDosing=myButtons.addButton(170,80,130,60,"Dosing");
    SettingsOutlet=myButtons.addButton(170,160,130,60,"Outlet");
    myButtons.drawButton(SettingsBack);
    myButtons.drawButton(SettingsLight);
    myButtons.drawButton(SettingsDosing);
    myButtons.drawButton(SettingsCO2);
    myButtons.drawButton(SettingsOutlet);

}//settingsScreen

void lightScreen()
{
    myGLCD.clrScr();
    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setFont(GroteskBold24x48);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.print("LIGHTS",CENTER,100);
    
}//lightScreen

void co2Screen()
{
    myGLCD.clrScr();
    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setFont(GroteskBold24x48);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.print("CO2",CENTER,100);
    
}//co2Screen

void dosingScreen()
{
    myGLCD.clrScr();
    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setFont(GroteskBold24x48);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.print("Dosing",CENTER,100);
    
}//dosingScreen

void outletScreen()
{
    myGLCD.clrScr();
    myGLCD.fillScr(VGA_SILVER);
    myGLCD.setBackColor(VGA_SILVER);
    myGLCD.setFont(GroteskBold24x48);
    myGLCD.setColor(VGA_NAVY);
    myGLCD.print("Outlets",CENTER,100);
    
}//outletScreen

THAT WAS IT!!!!!!!

Thank you so much!!! I've been racking my brain for hours!