Arduino Giga Crashing

Hi,

At the point marked by a comment in the code below, the Arduino Giga seems to crash as it blinks a red LED. I am in need of insight to determine why that is. Thank you.

#include "Arduino_GigaDisplayTouch.h"
#include "Arduino_GigaDisplay_GFX.h"

Arduino_GigaDisplayTouch touchDetector;
GigaDisplay_GFX display;

#define BLUE 0x0000ff
#define WHITE 0xffffff
#define BLACK 0x0000
#define GREY 0xef7d

String equation = "";
String temporaryString = "";
int contacts, counter;
int total = 0;

void setup() {
  delay(5000);

  Serial.begin(115200);
  while(!Serial);

  if (touchDetector.begin()) {
    Serial.print("Touch controller init - OK");
  } else {
    Serial.print("Touch controller init - FAILED");
    while(1) ;
  }

  delay(3000);

  display.begin();
  display.fillScreen(BLACK);

  display.fillRect(20, 225, 95, 95, GREY);

  display.fillRect(20, 340, 95, 95, GREY);
  display.fillRect(135, 340, 95, 95, BLUE);
  display.fillRect(250, 340, 95, 95, BLUE);
  display.fillRect(365, 340, 95, 95, BLUE);

  display.fillRect(20, 455, 95, 95, GREY);
  display.fillRect(135, 455, 95, 95, BLUE);
  display.fillRect(250, 455, 95, 95, BLUE);
  display.fillRect(365, 455, 95, 95, BLUE);

  display.fillRect(20, 570, 95, 95, GREY);
  display.fillRect(135, 570, 95, 95, BLUE);
  display.fillRect(250, 570, 95, 95, BLUE);
  display.fillRect(365, 570, 95, 95, BLUE);

  display.fillRect(20, 685, 95, 95, GREY);
  display.fillRect(135, 685, 95, 95, BLUE);
  display.fillRect(250, 685, 210, 95, BLUE);

  display.setTextColor(BLACK);
  display.setTextSize(5); 

  display.setCursor(55, 255);
  display.print("C");
  display.setCursor(55, 370);
  display.print("+");
  display.setCursor(55, 485);
  display.print("-");
  display.setCursor(55, 600);
  display.print("*");
  display.setCursor(55, 715);
  display.print("/");

  display.setTextColor(WHITE);

  display.setCursor(170, 370);
  display.print("7");
  display.setCursor(285, 370);
  display.print("8");
  display.setCursor(400, 370);
  display.print("9");

  display.setCursor(170, 485);
  display.print("4");
  display.setCursor(285, 485);
  display.print("5");
  display.setCursor(400, 485);
  display.print("6");

  display.setCursor(170, 600);
  display.print("1");
  display.setCursor(285, 600);
  display.print("2");
  display.setCursor(400, 600);
  display.print("3");

  display.setCursor(170, 715);
  display.print("0");
  display.setCursor(345, 715);
  display.print("=");
}

void loop() {
  uint8_t contacts;
  GDTpoint_t points[5];
  
  contacts = touchDetector.getTouchPoints(points);

  if (contacts > 0) {
    counter++;

    String character = characterPressed(points[0].x, points[0].y);

    if (counter > 5) {
      if (character == "E") calculate(equation);
      else if (character == "C") equation = "";
      else if (isNumber(character)) equation += character;
      else if (equation.length() > 0 && isNumber(equation.substring(equation.length() - 1))) equation += character;
      
      delay(250);

      counter = 0;
    }
   
  }
}

int calculate(String equation) {
  Serial.println(equation);
  
  total = equation.substring(0, 1).toInt();

  for (int i = 1; i <= equation.length(); i++) {
    if (isNumber(equation.substring(i, i + 1))) {
      if (isNumber(temporaryString)) temporaryString += equation.substring(i, i + 1);
      else {
        if (temporaryString == "+") total += temporaryString.toInt();
        if (temporaryString == "-") total -= temporaryString.toInt();
        if (temporaryString == "*") total *= temporaryString.toInt();
        if (temporaryString == "/") total /= temporaryString.toInt();

        temporaryString = "";
      }
    }
  }
  Serial.println(total);

  return total;
  
}

String characterPressed(int x, int y) { // after this function runs a few times the Giga crashes
  if (x > 20 && x < 115 && y > 255 && y < 350) return "C";

  if (x > 20 && x < 115 && y > 370 && y < 465) return "+";
  if (x > 20 && x < 115 && y > 485 && y < 580) return "-";
  if (x > 20 && x < 115 && y > 600 && y < 695) return "*";
  if (x > 20 && x < 115 && y > 715 && y < 810) return "/";

  if (x > 135 && x < 230 && y > 370 && y < 465) return "7";
  if (x > 250 && x < 345 && y > 370 && y < 465) return "8";
  if (x > 390 && x < 485 && y > 370 && y < 465) return "9";

  if (x > 135 && x < 230 && y > 485 && y < 580) return "4";
  if (x > 250 && x < 345 && y > 485 && y < 580) return "5";
  if (x > 390 && x < 485 && y > 485 && y < 580) return "6";

  if (x > 135 && x < 230 && y > 600 && y < 695) return "1";
  if (x > 250 && x < 345 && y > 600 && y < 695) return "2";
  if (x > 390 && x < 485 && y > 600 && y < 695) return "3";

  if (x > 135 && x < 230 && y > 715 && y < 810) return "0";
  if (x > 250 && x < 485 && y > 715 && y < 810) return "E";
}

bool isNumber(String c) {
  return c == "1" || c == "2" || c == "3" || c == "4" || c == "5" || c == "6" || c == "7" || c == "8" || c == "9"; 
}

Just following up to see if anyone has thoughts on how to resolve this.

Hi @mfusco I suggest adding a return "X"; to the end of characterPressed. It may be falling through if none of the above conditions are met.