SeanMabli2
Published

Arduino Calculator

You can use a touchscreen display and an Arduino to make a functioning calculator.

IntermediateFull instructions provided2,233
Arduino Calculator

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Touchscreen Display
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Arduino Calculator

Arduino
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

// Color definitions
#define BLACK       0x0000
#define NAVY        0x000F
#define DARKGREEN   0x03E0
#define DARKCYAN    0x03EF
#define MAROON      0x7800
#define PURPLE      0x780F
#define OLIVE       0x7BE0
#define LIGHTGREY   0xC618
#define DARKGREY    0x7BEF
#define BLUE        0x001F
#define GREEN       0x07E0
#define CYAN        0x07FF
#define RED         0xF800
#define PINK        0xF81F
#define YELLOW      0xFFE0
#define WHITE       0xFFFF
#define ORANGE      0xFD20
#define GREENYELLOW 0xAFE5

#define YP A2
#define XM A3
#define YM 8
#define XP 9

#define TS_MINX 130
#define TS_MAXX 905

#define TS_MINY 75
#define TS_MAXY 930

#define STATUS_X 10
#define STATUS_Y 65

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

long   number_1_long;
long   number_2_long;
long   number_3_long;
long   number_4_long;
long   equation_solved_long;
float  number_1_float;
float  number_2_float;
float  number_3_float;
float  number_4_float;
float  equation_solved_float;
int    character_count = 0;
int    current_number;
int    button_color = 0xFD20; // Default is orange
int    settings_count = 1;
String operation_1 = "#";
String operation_2 = "#";
String operation_3 = "#";
String current_operation;
String last_character;
String last_num_opt;
String equation_display;
String number_1_string;
String number_2_string;
String number_3_string;
String number_4_string;
bool   operation_press = false;
bool   number_1_done = false;
bool   number_2_done = false;
bool   number_3_done = false;
bool   number_4_done = false;
bool   operation_1_done = false;
bool   operation_2_done = false;
bool   operation_3_done = false;
bool   display_tft = false;
bool   display_solved = false;
bool   div_remainder;
bool   setting_open = false;
bool   color_window_opened = true;

void setup(void) {
  Serial.begin(9600);

  tft.reset();

  uint16_t identifier = tft.readID();

  tft.begin(identifier);
  tft.setRotation(0);

  Button_Setup();
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop(void) {
  if (setting_open == false) {
    Read_Number();
    Equation_Display();
    if ((number_1_done == true) && (display_tft == true)) {
      tft.setCursor(15, 20);
      tft.setTextColor(WHITE);
      tft.setTextSize(4);
      tft.println(equation_display);
      display_tft = false;
    }
    if (display_solved == true && div_remainder == false) {
      tft.fillRect(50, 81, 270, 78, BLACK);
      tft.setCursor(55, 100);
      tft.setTextColor(WHITE);
      tft.setTextSize(4);
      tft.println(equation_solved_long);
      display_solved = false;
    }
    if (display_solved == true && div_remainder == true) {
      tft.fillRect(50, 81, 270, 78, BLACK);
      tft.setCursor(55, 100);
      tft.setTextColor(WHITE);
      tft.setTextSize(4);
      tft.println(equation_solved_float);
      display_solved = false;
    }
  }
  if (setting_open == true) {
    if (settings_count == 1) {
      Setting_Color_Setup();
    }
    else {
      if (color_window_opened == true) {
        Settings_Color_Read_Button();
      }
      else {
        Settings_Tech_Read_Button();
      }
    }
  }
}

Assign Number

Arduino
void Assign_Number() {
  if ((operation_3_done == true) && (character_count == 3)) {
    number_4_long = (10 * number_4_long) + current_number;
    number_4_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_4_long";
  }
  if ((operation_3_done == true) && (character_count == 2)) {
    number_4_long = (10 * number_4_long) + current_number;
    number_4_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_4_long";
  }
  if ((operation_3_done == true) && (character_count == 1)) {
    number_4_long = (10 * number_4_long) + current_number;
    number_4_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_4_long";
  }
  if ((operation_3_done == true) && (character_count == 0)) {
    number_4_long = current_number;
    number_4_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_4_long";
  }
  if ((operation_2_done == true) && (operation_3_done == false) && (character_count == 3)) {
    number_3_long = (10 * number_3_long) + current_number;
    number_3_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_3_long";
  }
  if ((operation_2_done == true) && (operation_3_done == false) && (character_count == 2)) {
    number_3_long = (10 * number_3_long) + current_number;
    number_3_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_3_long";
  }
  if ((operation_2_done == true) && (operation_3_done == false) && (character_count == 1)) {
    number_3_long = (10 * number_3_long) + current_number;
    number_3_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_3_long";
  }
  if ((operation_2_done == true) && (operation_3_done == false) && (character_count == 0)) {
    number_3_long = current_number;
    number_3_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_3_long";
  }
  if ((operation_1_done == true) && (operation_2_done == false) && (character_count == 3)) {
    number_2_long = (10 * number_2_long) + current_number;
    number_2_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_2_long";
  }
  if ((operation_1_done == true) && (operation_2_done == false) && (character_count == 2)) {
    number_2_long = (10 * number_2_long) + current_number;
    number_2_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_2_long";
  }
  if ((operation_1_done == true) && (operation_2_done == false) && (character_count == 1)) {
    number_2_long = (10 * number_2_long) + current_number;
    number_2_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_2_long";
  }
  if ((operation_1_done == true) && (operation_2_done == false) && (character_count == 0)) {
    number_2_long = current_number;
    number_2_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_2_long";
  }
  if ((operation_1 == "#") && (character_count == 3)) {
    number_1_long = (10 * number_1_long) + current_number;
    number_1_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_1_long";
  }
  if ((operation_1 == "#") && (character_count == 2)) {
    number_1_long = (10 * number_1_long) + current_number;
    number_1_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_1_long";
  }
  if ((operation_1 == "#") && (character_count == 1)) {
    number_1_long = (10 * number_1_long) + current_number;
    number_1_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_1_long";
  }
  if ((operation_1 == "#") && (character_count == 0)) {
    number_1_long = current_number;
    number_1_done = true;
    character_count = character_count + 1;
    last_num_opt = "number_1_long";
  }
  last_character = current_number;
}

Assign Operation

Arduino
void Assign_Operation() {
  if ((operation_2 != "#") && (operation_press == true)) {
    operation_3 = current_operation;
    character_count = 0;
    operation_press = false;
    operation_3_done = true;
    last_num_opt = "operation_3";
  }
  if ((operation_1 != "#") && (operation_press == true)) {
    operation_2 = current_operation;
    character_count = 0;
    operation_press = false;
    operation_2_done = true;
    last_num_opt = "operation_2";
  }
  if ((operation_1 == "#") && (operation_press == true)) {
    operation_1 = current_operation;
    character_count = 0;
    operation_press = false;
    operation_1_done = true;
    last_num_opt = "operation_1";
  }
}

Backspace

Arduino
void Backspace() {
  if (last_num_opt == "number_1_long") {
    tft.setCursor(15, 20);
    tft.setTextColor(BLACK);
    tft.setTextSize(4);
    tft.println(equation_display);
    number_1_string = number_1_long;
    if (number_1_string.length() == 1) {
      number_1_done = false;
    }
    number_1_long = number_1_long - last_character.toInt();
    number_1_long = number_1_long / 10;
    character_count = character_count - 1;
    display_tft = true;
  }
  if (last_num_opt == "operation_1") {
    tft.setCursor(15, 20);
    tft.setTextColor(BLACK);
    tft.setTextSize(4);
    tft.println(equation_display);
    last_num_opt = "number_1_long";
    operation_1 = "#";
    number_1_string = number_1_long;
    character_count = number_1_string.length();
    operation_1_done = false;
    display_tft = true;
  }
  if (last_num_opt == "number_2_long") {
    tft.setCursor(15, 20);
    tft.setTextColor(BLACK);
    tft.setTextSize(4);
    tft.println(equation_display);
    number_2_string = number_2_long;
    if (number_2_string.length() == 1) {
      number_2_done = false;
      last_num_opt = "operation_1";
    }
    number_2_long = number_2_long - last_character.toInt();
    number_2_long = number_2_long / 10;
    character_count = character_count - 1;
    display_tft = true;
  }
  if (last_num_opt == "operation_2") {
    tft.setCursor(15, 20);
    tft.setTextColor(BLACK);
    tft.setTextSize(4);
    tft.println(equation_display);
    operation_2 = "#";
    operation_2_done = false;
    number_2_string = number_2_long;
    character_count = number_2_string.length();
    last_num_opt = "number_2_long";
    display_tft = true;
  }
  if (last_num_opt == "number_3_long") {
    tft.setCursor(15, 20);
    tft.setTextColor(BLACK);
    tft.setTextSize(4);
    tft.println(equation_display);
    number_3_string = number_3_long;
    if (number_3_string.length() == 1) {
      number_3_done = false;
      last_num_opt = "operation_2";
    }
    number_3_long = number_3_long - last_character.toInt();
    number_3_long = number_3_long / 10;
    character_count = character_count - 1;
    display_tft = true;
  }
  if (last_num_opt == "operation_3") {
    tft.setCursor(15, 20);
    tft.setTextColor(BLACK);
    tft.setTextSize(4);
    tft.println(equation_display);
    operation_3 = "#";
    operation_3_done = false;
    number_3_string = number_3_long;
    character_count = number_3_string.length();
    last_num_opt = "number_3_long";
    display_tft = true;
  }
  if (last_num_opt == "number_4_long") {
    tft.setCursor(15, 20);
    tft.setTextColor(BLACK);
    tft.setTextSize(4);
    tft.println(equation_display);
    number_4_string = number_4_long;
    if (number_4_string.length() == 1) {
      number_4_done = false;
      last_num_opt = "operation_3";
    }
    number_4_long = number_4_long - last_character.toInt();
    number_4_long = number_4_long / 10;
    character_count = character_count - 1;
    display_tft = true;
  }
}

Button Setup

Arduino
void Button_Setup() {
  tft.fillScreen(BLACK);
  tft.fillRect(0, 80, 320, 1, WHITE);
  tft.setCursor(15, 100);
  tft.setTextColor(WHITE);
  tft.setTextSize(4);
  tft.println("=");
  tft.fillRect(0, 160, 160, 64, button_color);
  tft.drawRect(0, 160, 160, 64, WHITE);
  tft.setCursor(10, 182);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.println("Settings");
  tft.fillRect(0, 224, 80, 64, button_color);
  tft.drawRect(0, 224, 80, 64, WHITE);
  tft.setCursor(23, 239);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("7");
  tft.fillRect(0, 288, 80, 64, button_color);
  tft.drawRect(0, 288, 80, 64, WHITE);
  tft.setCursor(23, 303);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("4");
  tft.fillRect(0, 352, 80, 64, button_color);
  tft.drawRect(0, 352, 80, 64, WHITE);
  tft.setCursor(23, 366);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("1");
  tft.fillRect(0, 416, 80, 64, button_color);
  tft.drawRect(0, 416, 80, 64, WHITE);
  tft.setCursor(10, 441);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Clear");
  tft.fillRect(80, 224, 80, 64, button_color);
  tft.drawRect(80, 224, 80, 64, WHITE);
  tft.setCursor(103, 239);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("8");
  tft.fillRect(80, 288, 80, 64, button_color);
  tft.drawRect(80, 288, 80, 64, WHITE);
  tft.setCursor(103, 303);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("5");
  tft.fillRect(80, 352, 80, 64, button_color);
  tft.drawRect(80, 352, 80, 64, WHITE);
  tft.setCursor(103, 366);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("2");
  tft.fillRect(80, 416, 80, 64, button_color);
  tft.drawRect(80, 416, 80, 64, WHITE);
  tft.setCursor(103, 431);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("0");
  tft.fillRect(160, 160, 160, 64, button_color);
  tft.drawRect(160, 160, 160, 64, WHITE);
  tft.setCursor(187, 182);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.println("Delete");
  tft.fillRect(160, 224, 80, 64, button_color);
  tft.drawRect(160, 224, 80, 64, WHITE);
  tft.setCursor(183, 239);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("9");
  tft.fillRect(160, 288, 80, 64, button_color);
  tft.drawRect(160, 288, 80, 64, WHITE);
  tft.setCursor(183, 303);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("6");
  tft.fillRect(160, 352, 80, 64, button_color);
  tft.drawRect(160, 352, 80, 64, WHITE);
  tft.setCursor(183, 366);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("3");
  tft.fillRect(160, 416, 80, 64, button_color);
  tft.drawRect(160, 416, 80, 64, WHITE);
  tft.setCursor(183, 431);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("=");
  tft.fillRect(240, 224, 80, 64, button_color);
  tft.drawRect(240, 224, 80, 64, WHITE);
  tft.setCursor(263, 239);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("+");
  tft.fillRect(240, 288, 80, 64, button_color);
  tft.drawRect(240, 288, 80, 64, WHITE);
  tft.setCursor(263, 303);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("-");
  tft.fillRect(240, 352, 80, 64, button_color);
  tft.drawRect(240, 352, 80, 64, WHITE);
  tft.setCursor(263, 357);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("x");
  tft.fillRect(240, 416, 80, 64, button_color);
  tft.drawRect(240, 416, 80, 64, WHITE);
  tft.setCursor(263, 431);
  tft.setTextColor(WHITE);
  tft.setTextSize(5);
  tft.println("/");
}

Calculate

Arduino
void Calculate() {
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true)) {
    if (operation_1 == "+") {
      equation_solved_long = number_1_long + number_2_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-") {
      equation_solved_long = number_1_long - number_2_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*") {
      equation_solved_long = number_1_long * number_2_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float;
        div_remainder = true;
      }
      display_solved = true;
    }
  }
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true) && (operation_2_done == true) && (number_3_done == true)) {
    if (operation_1 == "+" && operation_2 == "+") {
      equation_solved_long = number_1_long + number_2_long + number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "+") {
      equation_solved_long = number_1_long - number_2_long + number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "+") {
      equation_solved_long = number_1_long * number_2_long + number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "+") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float + number_3_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float + number_3_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "-") {
      equation_solved_long = number_1_long + number_2_long - number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "-") {
      equation_solved_long = number_1_long - number_2_long - number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "-") {
      equation_solved_long = number_1_long * number_2_long - number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "-") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float - number_3_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float - number_3_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "*") {
      equation_solved_long = number_1_long + number_2_long * number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "*") {
      equation_solved_long = number_1_long - number_2_long * number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "*") {
      equation_solved_long = number_1_long * number_2_long * number_3_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "*") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float * number_3_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float * number_3_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "/") {
      number_3_float = number_3_long;
      if (number_2_long % number_3_long == 0) {
        equation_solved_long = number_1_long + number_2_long / number_3_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long + number_2_long / number_3_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "/") {
      number_3_float = number_3_long;
      if (number_2_long % number_3_long == 0) {
        equation_solved_long = number_1_long - number_2_long / number_3_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long - number_2_long / number_3_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "/") {
      number_3_float = number_3_long;
      if (number_2_long % number_3_long == 0) {
        equation_solved_long = number_1_long * number_2_long / number_3_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long * number_2_long / number_3_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "/") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_3_float = number_3_long;
      if (number_1_long % number_2_long == 0 && ((number_1_long / number_2_long) % number_3_long == 0)) {
        equation_solved_long = number_1_float / number_2_float / number_3_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float / number_3_float;
        div_remainder = true;
      }
      display_solved = true;
    }
  }
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true) && (operation_2_done == true) && (number_3_done == true) && (operation_3_done == true) && (number_4_done == true)) {
    if (operation_1 == "+" && operation_2 == "+" && operation_3 == "+") {
      equation_solved_long = number_1_long + number_2_long + number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "+" && operation_3 == "+") {
      equation_solved_long = number_1_long - number_2_long + number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "+" && operation_3 == "+") {
      equation_solved_long = number_1_long * number_2_long + number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "+" && operation_3 == "+") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float + number_3_long + number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float + number_3_long + number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "-" && operation_3 == "+") {
      equation_solved_long = number_1_long + number_2_long - number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "-" && operation_3 == "+") {
      equation_solved_long = number_1_long - number_2_long - number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "-" && operation_3 == "+") {
      equation_solved_long = number_1_long * number_2_long - number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "-" && operation_3 == "+") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float - number_3_long + number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float - number_3_long + number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "*" && operation_3 == "+") {
      equation_solved_long = number_1_long + number_2_long * number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "*" && operation_3 == "+") {
      equation_solved_long = number_1_long - number_2_long * number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "*" && operation_3 == "+") {
      equation_solved_long = number_1_long * number_2_long * number_3_long + number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "*" && operation_3 == "+") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float * number_3_long + number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float * number_3_long + number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "/" && operation_3 == "+") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long + number_2_long / number_3_float + number_4_long;
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "/" && operation_3 == "+") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long - number_2_long / number_3_float + number_4_long;
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "/" && operation_3 == "+") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long * number_2_long / number_3_float + number_4_long;
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "/" && operation_3 == "+") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_3_float = number_3_long;
      if (number_1_long % number_2_long == 0 && ((number_1_long / number_2_long) % number_3_long == 0)) {
        equation_solved_long = number_1_float / number_2_float / number_3_float + number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float / number_3_float + number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "+" && operation_3 == "-") {
      equation_solved_long = number_1_long + number_2_long + number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "+" && operation_3 == "-") {
      equation_solved_long = number_1_long - number_2_long + number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "+" && operation_3 == "-") {
      equation_solved_long = number_1_long * number_2_long + number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "+" && operation_3 == "-") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float + number_3_long - number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float + number_3_long - number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "-" && operation_3 == "-") {
      equation_solved_long = number_1_long + number_2_long - number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "-" && operation_3 == "-") {
      equation_solved_long = number_1_long - number_2_long - number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "-" && operation_3 == "-") {
      equation_solved_long = number_1_long * number_2_long - number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "-" && operation_3 == "-") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float - number_3_long - number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float - number_3_long - number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "*" && operation_3 == "-") {
      equation_solved_long = number_1_long + number_2_long * number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "*" && operation_3 == "-") {
      equation_solved_long = number_1_long - number_2_long * number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "*" && operation_3 == "-") {
      equation_solved_long = number_1_long * number_2_long * number_3_long - number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "*" && operation_3 == "-") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float * number_3_long - number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float * number_3_long - number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "/" && operation_3 == "-") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long + number_2_long / number_3_float - number_4_long;
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "/" && operation_3 == "-") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long - number_2_long / number_3_float - number_4_long;
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "/" && operation_3 == "-") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long * number_2_long / number_3_float - number_4_long;
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "/" && operation_3 == "-") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_3_float = number_3_long;
      if (number_1_long % number_2_long == 0 && ((number_1_long / number_2_long) % number_3_long == 0)) {
        equation_solved_long = number_1_float / number_2_float / number_3_float - number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float / number_3_float - number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "+" && operation_3 == "*") {
      equation_solved_long = number_1_long + number_2_long + number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "+" && operation_3 == "*") {
      equation_solved_long = number_1_long - number_2_long + number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "+" && operation_3 == "*") {
      equation_solved_long = number_1_long * number_2_long + number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "+" && operation_3 == "*") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float + number_3_long * number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float + number_3_long * number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "-" && operation_3 == "*") {
      equation_solved_long = number_1_long + number_2_long - number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "-" && operation_3 == "*") {
      equation_solved_long = number_1_long - number_2_long - number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "-" && operation_3 == "*") {
      equation_solved_long = number_1_long * number_2_long - number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "-" && operation_3 == "*") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float - number_3_long * number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float - number_3_long * number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "*" && operation_3 == "*") {
      equation_solved_long = number_1_long + number_2_long * number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "-" && operation_2 == "*" && operation_3 == "*") {
      equation_solved_long = number_1_long - number_2_long * number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "*" && operation_2 == "*" && operation_3 == "*") {
      equation_solved_long = number_1_long * number_2_long * number_3_long * number_4_long;
      display_solved = true;
      div_remainder = false;
    }
    if (operation_1 == "/" && operation_2 == "*" && operation_3 == "*") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      if (number_1_long % number_2_long == 0) {
        equation_solved_long = number_1_float / number_2_float * number_3_long * number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float * number_3_long * number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "/" && operation_3 == "*") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long + number_2_long / number_3_float * number_4_long;
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "/" && operation_3 == "*") {
      number_3_float = number_3_long;
      equation_solved_float = number_1_long - number_2_long / number_3_float * number_4_long;
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "/" && operation_3 == "*") {
      number_3_float = number_3_long;
      equation_solved_float    = number_1_long * number_2_long / number_3_float * number_4_long;
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "/" && operation_3 == "*") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_3_float = number_3_long;
      if (number_1_long % number_2_long == 0 && ((number_1_long / number_2_long) % number_3_long == 0)) {
        equation_solved_long = number_1_float / number_2_float / number_3_float * number_4_long;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float / number_3_float * number_4_long;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "+" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long + number_2_long + number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long + number_2_long + number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "+" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long - number_2_long + number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long - number_2_long + number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "+" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long * number_2_long + number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long * number_2_long + number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "+" && operation_3 == "/") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_4_float = number_4_long;
      if (number_1_long % number_2_long == 0 && number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_float / number_2_float + number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float + number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "-" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long + number_2_long - number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long + number_2_long - number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "-" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long - number_2_long - number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long - number_2_long - number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "-" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long * number_2_long - number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long * number_2_long - number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "-" && operation_3 == "/") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_4_float = number_4_long;
      if (number_1_long % number_2_long == 0 && number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_float / number_2_float - number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float - number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "*" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long + number_2_long * number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long + number_2_long * number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "*" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long - number_2_long * number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long - number_2_long * number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "*" && operation_3 == "/") {
      number_4_float = number_4_long;
      if (number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_long * number_2_long * number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long * number_2_long * number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "*" && operation_3 == "/") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_4_float = number_4_long;
      if (number_1_long % number_2_long == 0 && number_3_long % number_4_long == 0) {
        equation_solved_long = number_1_float / number_2_float * number_3_long / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float * number_3_long / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "+" && operation_2 == "/" && operation_3 == "/") {
      number_4_float = number_4_long;
      number_3_float = number_3_long;
      if (number_2_long % number_3_long == 0 && ((number_2_long / number_3_long) % number_4_long == 0)) {
        equation_solved_long = number_1_long + number_2_long / number_3_float / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long + number_2_long / number_3_float / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "-" && operation_2 == "/" && operation_3 == "/") {
      number_4_float = number_4_long;
      number_3_float = number_3_long;
      if (number_2_long % number_3_long == 0 && ((number_2_long / number_3_long) % number_4_long == 0)) {
        equation_solved_long = number_1_long - number_2_long / number_3_float / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long - number_2_long / number_3_float / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "*" && operation_2 == "/" && operation_3 == "/") {
      number_4_float = number_4_long;
      number_3_float = number_3_long;
      if (number_2_long % number_3_long == 0 && ((number_2_long / number_3_long) % number_4_long == 0)) {
        equation_solved_long = number_1_long * number_2_long / number_3_float / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_long * number_2_long / number_3_float / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
    if (operation_1 == "/" && operation_2 == "/" && operation_3 == "/") {
      number_1_float = number_1_long;
      number_2_float = number_2_long;
      number_3_float = number_3_long;
      number_4_float = number_4_long;
      if (number_1_long % number_2_long == 0 && ((number_1_long / number_2_long) % number_3_long == 0) && ((number_1_long / number_2_long / number_3_long) % number_4_long == 0)) {
        equation_solved_long = number_1_float / number_2_float / number_3_float / number_4_float;
        div_remainder = false;
      }
      else {
        equation_solved_float = number_1_float / number_2_float / number_3_float / number_4_float;
        div_remainder = true;
      }
      display_solved = true;
    }
  }
}

Equation Display

Arduino
void Equation_Display() {
  if (number_1_done == true) {
    equation_display = number_1_long;
  }
  if ((number_1_done == true) && (operation_1_done == true)) {
    equation_display = number_1_long + operation_1;
  }
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true)) {
    equation_display = number_1_long + operation_1 + number_2_long;
  }
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true) && (operation_2_done == true)) {
    equation_display = number_1_long + operation_1 + number_2_long + operation_2;
  }
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true) && (operation_2_done == true) && (number_3_done == true)) {
    equation_display = number_1_long + operation_1 + number_2_long + operation_2 + number_3_long;
  }
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true) && (operation_2_done == true) && (number_3_done == true) && (operation_3_done == true)) {
    equation_display = number_1_long + operation_1 + number_2_long + operation_2 + number_3_long + operation_3;
  }
  if ((number_1_done == true) && (operation_1_done == true) && (number_2_done == true) && (operation_2_done == true) && (number_3_done == true) && (operation_3_done == true) && (number_4_done == true)) {
    equation_display = number_1_long + operation_1 + number_2_long + operation_2 + number_3_long + operation_3 + number_4_long;
  }
}

Read Number

Arduino
void Read_Number() {
  TSPoint p = ts.getPoint();

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
    p.x = map(p.x, TS_MAXX, TS_MINX, 480, 0);
    p.y = map(p.y, TS_MAXY, TS_MINY, 0, 320);

    if (p.x > 160 && p.x < 224 && p.y > 0 && p.y < 160)
    {
      Serial.println("Settings Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      delay(300);
      setting_open = true;
    }
    if (p.x > 224 && p.x < 288 && p.y > 0 && p.y < 80 && equation_display.length() < 11)
    {
      Serial.println("7 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 7;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 0 && p.y < 80 && equation_display.length() < 11)
    {
      Serial.println("4 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 4;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 0 && p.y < 80 && equation_display.length() < 11)
    {
      Serial.println("1 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 1;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 0 && p.y < 80)
    {
      Serial.println("Clear Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      delay(300);
      number_1_long = 0;
      number_2_long = 0;
      number_3_long = 0;
      number_4_long = 0;
      number_1_float = 0;
      number_2_float = 0;
      number_3_float = 0;
      number_4_float = 0;
      operation_1 = "#";
      operation_2 = "#";
      operation_3 = "#";
      character_count = 0;
      current_number = 0;
      current_operation = "#";
      operation_press = false;
      number_1_done = false;
      number_2_done = false;
      number_3_done = false;
      number_4_done = false;
      operation_1_done = false;
      operation_2_done = false;
      operation_3_done = false;
      display_tft = false;
      display_solved = false;
      equation_display = ".";
      tft.fillRect(0, 0, 320, 160, BLACK);
      tft.fillRect(0, 80, 320, 1, WHITE);
      tft.setCursor(15, 100);
      tft.setTextColor(WHITE);
      tft.setTextSize(4);
      tft.println("=");
    }
    if (p.x > 224 && p.x < 288 && p.y > 80 && p.y < 160 && equation_display.length() < 11)
    {
      Serial.println("8 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 8;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 80 && p.y < 160 && equation_display.length() < 11)
    {
      Serial.println("5 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 5;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 80 && p.y < 160 && equation_display.length() < 11)
    {
      Serial.println("2 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 2;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 80 && p.y < 160 && equation_display.length() < 11)
    {
      Serial.println("0 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 0;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 160 && p.x < 224 && p.y > 160 && p.y < 320)
    {
      Serial.println("Backspace Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      delay(300);
      Backspace();
    }
    if (p.x > 224 && p.x < 288 && p.y > 160 && p.y < 240 && equation_display.length() < 11)
    {
      Serial.println("9 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 9;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 160 && p.y < 240 && equation_display.length() < 11)
    {
      Serial.println("6 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 6;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 160 && p.y < 240 && equation_display.length() < 11)
    {
      Serial.println("3 Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_number = 3;
      Assign_Number();
      display_tft = true;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 160 && p.y < 240)
    {
      Serial.println("= Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      delay(300);
      Calculate();
    }
    if (p.x > 224 && p.x < 288 && p.y > 240 && p.y < 320 && equation_display.length() < 11)
    {
      Serial.println("+ Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_operation = "+";
      operation_press = true;
      Assign_Operation();
      display_tft = true;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 240 && p.y < 320 && equation_display.length() < 11)
    {
      Serial.println("- Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_operation = "-";
      operation_press = true;
      Assign_Operation();
      display_tft = true;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 240 && p.y < 320 && equation_display.length() < 11)
    {
      Serial.println("x Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      current_operation = "*";
      operation_press = true;
      Assign_Operation();
      display_tft = true;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 240 && p.y < 320 && equation_display.length() < 11)
    {
      Serial.println("/ Pressed");
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      delay(300);
      current_operation = "/";
      operation_press = true;
      Assign_Operation();
      display_tft = true;
      delay(300);
    }
  }
}

Setting Color Setup

Arduino
void Setting_Color_Setup() {
  tft.fillScreen(BLACK);
  tft.fillRect(0, 0, 64, 64, BLACK);
  tft.drawRect(0, 0, 64, 64, WHITE);
  tft.setCursor(10, 20);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.println("Cal");
  tft.fillRect(64, 0, 128, 64, BLACK);
  tft.drawRect(64, 0, 128, 64, WHITE);
  tft.setCursor(85, 20);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.println("Color");
  tft.fillRect(192, 0, 128, 64, BLACK);
  tft.drawRect(192, 0, 128, 64, WHITE);
  tft.setCursor(215, 20);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.println("Tech");
  tft.setCursor(55, 90);
  tft.setTextColor(WHITE);
  tft.setTextSize(6);
  tft.println("Button");
  tft.setCursor(70, 140);
  tft.setTextColor(WHITE);
  tft.setTextSize(6);
  tft.println("Color");
  tft.fillRect(30, 200, 260, 1, WHITE);
  tft.fillRect(0, 224, 80, 64, RED);
  tft.drawRect(0, 224, 80, 64, WHITE);
  tft.setCursor(20, 249);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Red");
  tft.fillRect(0, 288, 80, 64, GREEN);
  tft.drawRect(0, 288, 80, 64, WHITE);
  tft.setCursor(10, 313);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Green");
  tft.fillRect(0, 352, 80, 64, BLUE);
  tft.drawRect(0, 352, 80, 64, WHITE);
  tft.setCursor(15, 377);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Blue");
  tft.fillRect(0, 416, 80, 64, YELLOW);
  tft.drawRect(0, 416, 80, 64, WHITE);
  tft.setCursor(5, 441);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Yellow");
  tft.fillRect(80, 224, 80, 64, MAROON);
  tft.drawRect(80, 224, 80, 64, WHITE);
  tft.setCursor(85, 249);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Maroon");
  tft.fillRect(80, 288, 80, 64, DARKGREEN);
  tft.drawRect(80, 288, 80, 64, WHITE);
  tft.setCursor(100, 303);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Dark");
  tft.setCursor(90, 323);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Green");
  tft.fillRect(80, 352, 80, 64, NAVY);
  tft.drawRect(80, 352, 80, 64, WHITE);
  tft.setCursor(100, 377);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Navy");
  tft.fillRect(80, 416, 80, 64, ORANGE);
  tft.drawRect(80, 416, 80, 64, WHITE);
  tft.setCursor(85, 441);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Orange");
  tft.fillRect(160, 224, 80, 64, PINK);
  tft.drawRect(160, 224, 80, 64, WHITE);
  tft.setCursor(180, 249);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Pink");
  tft.fillRect(160, 288, 80, 64, OLIVE);
  tft.drawRect(160, 288, 80, 64, WHITE);
  tft.setCursor(170, 313);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Olive");
  tft.fillRect(160, 352, 80, 64, DARKCYAN);
  tft.drawRect(160, 352, 80, 64, WHITE);
  tft.setCursor(180, 367);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Dark");
  tft.setCursor(180, 387);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Cyan");
  tft.fillRect(160, 416, 80, 64, LIGHTGREY);
  tft.drawRect(160, 416, 80, 64, WHITE);
  tft.setCursor(180, 441);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Gray");
  tft.fillRect(240, 224, 80, 64, PURPLE);
  tft.drawRect(240, 224, 80, 64, WHITE);
  tft.setCursor(245, 249);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Purple");
  tft.fillRect(240, 288, 80, 64, GREENYELLOW);
  tft.drawRect(240, 288, 80, 64, WHITE);
  tft.setCursor(250, 303);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Green");
  tft.setCursor(245, 323);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Yellow");
  tft.fillRect(240, 352, 80, 64, CYAN);
  tft.drawRect(240, 352, 80, 64, WHITE);
  tft.setCursor(260, 377);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Cyan");
  tft.fillRect(240, 416, 80, 64, BLACK);
  tft.drawRect(240, 416, 80, 64, WHITE);
  tft.setCursor(250, 441);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Black");
  settings_count = 0;
}

Setting Tech Setup

Arduino
void Setting_Tech_Setup() {
  tft.fillScreen(BLACK);
  tft.fillRect(0, 0, 64, 64, BLACK);
  tft.drawRect(0, 0, 64, 64, WHITE);
  tft.setCursor(10, 20);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.println("Cal");
  tft.fillRect(64, 0, 128, 64, BLACK);
  tft.drawRect(64, 0, 128, 64, WHITE);
  tft.setCursor(85, 20);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.println("Color");
  tft.fillRect(192, 0, 128, 64, BLACK);
    tft.drawRect(192, 0, 128, 64, WHITE);
    tft.setCursor(215, 20);
    tft.setTextColor(WHITE);
    tft.setTextSize(3);
    tft.println("Tech");
    tft.setCursor(80, 90);
    tft.setTextColor(WHITE);
    tft.setTextSize(6);
    tft.println("Tech");
    tft.setCursor(65, 140);
    tft.setTextColor(WHITE);
    tft.setTextSize(6);
    tft.println("Specs");
    tft.fillRect(30, 200, 260, 1, WHITE);
    tft.setCursor(15, 224);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.println("Compatable Devices:");
    tft.setCursor(15, 244);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.println("Arduino Mega 2560");
    tft.setCursor(15, 264);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.println("Arduino Due");
    tft.setCursor(15, 294);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.println("Flash Memory Size:");
    tft.setCursor(15, 314);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.println("53166  x bytes");  
  tft.setCursor(15, 344);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("Default Screen Size:");
  tft.setCursor(15, 364);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.println("3.5 in, 480*320");  
  settings_count = 0;
}

Settings Color Read Button

Arduino
void Settings_Color_Read_Button() {
  TSPoint p = ts.getPoint();

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
    p.x = map(p.x, TS_MAXX, TS_MINX, 480, 0);
    p.y = map(p.y, TS_MAXY, TS_MINY, 0, 320);

    if (p.x > 0 && p.x < 64 && p.y > 0 && p.y < 64)
    {
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      Button_Setup();
      setting_open = false;
      settings_count = 1;
      if (equation_display != ".") {
        tft.setCursor(15, 20);
        tft.setTextColor(WHITE);
        tft.setTextSize(4);
        tft.println(equation_display);
      }
      delay(300);
    }
    if (p.x > 0 && p.x < 64 && p.y > 192 && p.y < 320)
    {
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      Setting_Tech_Setup();
      color_window_opened = false;
      delay(300);
    }
    if (p.x > 224 && p.x < 288 && p.y > 0 && p.y < 80)
    {
      button_color = 0xF800;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 0 && p.y < 80)
    {
      button_color = 0x07E0;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 0 && p.y < 80)
    {
      button_color = 0x001F;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 0 && p.y < 80)
    {
      button_color = 0xFFE0;
      delay(300);
    }
    if (p.x > 224 && p.x < 288 && p.y > 80 && p.y < 160)
    {
      button_color = 0x7800;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 80 && p.y < 160)
    {
      button_color = 0x03E0;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 80 && p.y < 160)
    {
      button_color = 0x000F;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 80 && p.y < 160)
    {
      button_color = 0xFD20;
      delay(300);
    }
    if (p.x > 224 && p.x < 288 && p.y > 160 && p.y < 240)
    {
      button_color = 0xF81F;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 160 && p.y < 240)
    {
      button_color = 0x7BE0;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 160 && p.y < 240)
    {
      button_color = 0x03EF;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 160 && p.y < 240)
    {
      button_color = 0xC618;
      delay(300);
    }
    if (p.x > 224 && p.x < 288 && p.y > 240 && p.y < 320)
    {
      button_color = 0x780F;
      delay(300);
    }
    if (p.x > 288 && p.x < 352 && p.y > 240 && p.y < 320)
    {
      button_color = 0xAFE5;
      delay(300);
    }
    if (p.x > 352 && p.x < 416 && p.y > 240 && p.y < 320)
    {
      button_color = 0x07FF;
      delay(300);
    }
    if (p.x > 416 && p.x < 480 && p.y > 240 && p.y < 320)
    {
      button_color = 0x0000;
      delay(300);
    }
  }
}

Settings Tech Read Button

Arduino
void Settings_Tech_Read_Button() {
  TSPoint p = ts.getPoint();

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
    p.x = map(p.x, TS_MAXX, TS_MINX, 480, 0);
    p.y = map(p.y, TS_MAXY, TS_MINY, 0, 320);

    if (p.x > 0 && p.x < 64 && p.y > 0 && p.y < 64)
    {
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      Button_Setup();
      setting_open = false;
      settings_count = 1;
      if (equation_display != ".") {
        tft.setCursor(15, 20);
        tft.setTextColor(WHITE);
        tft.setTextSize(4);
        tft.println(equation_display);
      }
      delay(300);
    }
    if (p.x > 0 && p.x < 64 && p.y > 64 && p.y < 192)
    {
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      Setting_Color_Setup();
      color_window_opened = true;
      delay(300);
    }
  }
}

Credits

SeanMabli2

SeanMabli2

6 projects • 7 followers

Comments