Sketch is big, some tips on how I can shrink it?

The sketch below if filled with floats (I think I need them, but I hope I can remove a bunch). I am also displaying some graphics and a small amount of text used for debugging and field testing.
I am looking for tips on how to reduce the size of the sketch as I would like to implement some more features and logic for needed features in the near future. I am a noob when it comes to code. But willing to dive in and learn the ninja techniques if someone is willing to take a bit of time to explain where I am being incompetent.
Thanks

(code too long to attach to post) attached a file with the sketch(s)

You could turn some of these into loops:

  button0 = mcp.digitalRead(0);
  button1 = mcp.digitalRead(1);
  button2 = mcp.digitalRead(2);
  button3 = mcp.digitalRead(3);

...

      latitude.b[0] = rx.getData(0);
      latitude.b[1] = rx.getData(1);
      latitude.b[2] = rx.getData(2);
      latitude.b[3] = rx.getData(3);

...

  payload[0] = latitude.b[0];               
  payload[1] = latitude.b[1];
  payload[2] = latitude.b[2];
  payload[3] = latitude.b[3];

I suggest constants for your "conditions" - I would go mad trying to debug this:

      if(RxCondition == 0){
      condition = 4;
      }
  }

  if(button0 == LOW){ // Emergency
    condition = 1;
    
  }

  if(button1 == LOW){ // Caution
    condition = 2;
  }

  if(button2 == LOW){ //OK
    condition = 3;

Some constants like:

const byte RACE_START = 0;
const byte RACE_ACTIVE = 1;
const byte RACE_FINISHED = 2;

Or whatever-it-is that they mean. Ditto for button1, button2, button3.

Thanks Nick. Good idea regarding the loop's I will see how much space that saves me.

Yeah the condition statements was something that I just jammed a name to when I started building the sketch and never really gave it the thought it needed to make my life easier down the road. Will see if I can make it easier to understand.

You won't save thousands of bytes, but every bit counts.

More here:

  mcp.pinMode(0, INPUT); //pin 10 on Expander
  mcp.pinMode(1, INPUT); //pin 11 on Expander
  mcp.pinMode(2, INPUT); //pin 12 on Expander
  mcp.pinMode(3, INPUT); //pin 13 on Expander
  mcp.pullUp(0, HIGH);  // turn on a 100K pullup internally
  mcp.pullUp(1, HIGH);  // turn on a 100K pullup internally
  mcp.pullUp(2, HIGH);  // turn on a 100K pullup internally
  mcp.pullUp(3, HIGH);  // turn on a 100K pullup internally

  mcp.pinMode(4, OUTPUT); //pin 14 on Expander
  mcp.pinMode(5, OUTPUT); //pin 15 on Expander
  mcp.pinMode(6, OUTPUT); //pin 16 on Expander
  mcp.pinMode(7, OUTPUT); //pin 17 on Expander
  mcp.digitalWrite(4, HIGH);
  mcp.digitalWrite(5, HIGH);
  mcp.digitalWrite(6, HIGH);
  mcp.digitalWrite(7, HIGH);

Also, how large do these get?

int CarNumber = 1;
int condition = 0;
int OldCondition = 0;
int RxCar = 0;
int RxSpeed = 0;
int RxCondition = 0;
int RxOldCondition = 0;

If they can fit into a byte, use that. Generating code for 1-byte arithmetic often uses less space than larger data types.


  tft.setCursor(25, 0);
  tft.print(GPS.latitude);
  tft.print(GPS.lat);
  tft.setCursor(25, 8);
  tft.print(GPS.longitude, 4);
  tft.print(GPS.lon);

If space is tight I would be making a function that sets the cursor and then prints some text. Saves you repeating a lot of stuff.


   tft.setTextColor(RED);
   tft.println("Lat:");
   tft.println("Lon:");
   tft.println("Sat:"); 
   tft.println("kph:");
   tft.println("Alt:");

Will this work?

   tft.setTextColor(RED);
   tft.println("Lat:\nLon:\nSat:\nkph:\nAlt:");
   tft.println("Lat:\nLon:\nSat:\nkph:\nAlt:");

And if tft is derived from Print (which it appears to be, indirectly) you can save RAM like this:

   tft.println(F("Lat:\nLon:\nSat:\nkph:\nAlt:"));

Wow, brain hurts! will dig in and make these changes. Question regarding the tft.println(F("Lat:\nLon:\nSat:\nkph:\nAlt:"));
what is the F for?
Yes its a derivative of Print used for the tft library I am using.

Nice, down from 29,266 bytes to 28,208

I never thought for loops would slash so much!

I just spent a couple hours going through your website link. Thank you very much for that! I made quite a few changes and improvements to make my sketch allot easier to debug and read.