Numbers not printing sequentially

This is some code for a calculator (I haven't got code for the actual calculations yet), but every time I press one of the buttons, it prints it overtop of the last number. In other words, it isn't printing the numbers sequentially. Where is the code messed up?
It looks like the first line in the void loop is what is messing it up, but I don't know how to tell it to only set the cursor for the FIRST number.

#include "Adafruit_GFX.h"    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define BLACK 0x0000       /*   0,   0,   0 */
#define NAVY 0x000F        /*   0,   0, 128 */
#define DARKGREEN 0x03E0   /*   0, 128,   0 */
#define DARKCYAN 0x03EF    /*   0, 128, 128 */
#define MAROON 0x7800      /* 128,   0,   0 */
#define PURPLE 0x780F      /* 128,   0, 128 */
#define OLIVE 0x7BE0       /* 128, 128,   0 */
#define LIGHTGREY 0xC618   /* 192, 192, 192 */
#define DARKGREY 0x7BEF    /* 128, 128, 128 */
#define BLUE 0x001F        /*   0,   0, 255 */
#define GREEN 0x07E0       /*   0, 255,   0 */
#define CYAN 0x07FF        /*   0, 255, 255 */
#define RED 0xF800         /* 255,   0,   0 */
#define MAGENTA 0xF81F     /* 255,   0, 255 */
#define YELLOW 0xFFE0      /* 255, 255,   0 */
#define WHITE 0xFFFF       /* 255, 255, 255 */
#define ORANGE 0xFD20      /* 255, 165,   0 */
#define GREENYELLOW 0xAFE5 /* 173, 255,  47 */
#define PINK 0xF81F
#define DARKBLUE 0x0010
#define VIOLET 0x8888
#define GOLD 0xFEA0
#define BROWN 0xA145
#define SILVER 0xC618
#define LIME 0x07E0
#define ORANGERED 0xFA20

#include <XPT2046_Touchscreen.h>           // Hardware SPI library
char *name = "Shield XPT2046 Calibration";  //edit name of shield
const int TS_LANDSCAPE = 1; //XPT2046_TouchScreen.h
const int TS_LEFT = 261, TS_RT = 3770, TS_TOP = 3869, TS_BOT = 296;
#define XPT_CS  53      // MEGA2560 SHIELD 
#define XPT_IRQ 255     // XPT2046 library does not like IRQ
XPT2046_Touchscreen ts(XPT_CS, XPT_IRQ);

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
  bool pressed = ts.touched();
  if (pressed) {
    TS_Point p = ts.getPoint();
    if (TS_LANDSCAPE) mapxy(p.y, p.x);
    else mapxy(p.x, p.y);
  }
  return pressed;
}

void Touch_init(void)
{
  ts.begin();
}

void mapxy(int x, int y)                //maps ADC to pixel_x, pixel_y
{
  int aspect = tft.getRotation();     //LANDSCAPE
  int tft_width = tft.width();
  int tft_height = tft.height();
  switch (aspect & 3) {
    case 0:      //PORTRAIT
      pixel_x = map(x, TS_LEFT, TS_RT, 0, tft_width);
      pixel_y = map(y, TS_TOP, TS_BOT, 0, tft_height);
      break;
    case 1:      //LANDSCAPE
      pixel_x = map(y, TS_TOP, TS_BOT, 0, tft_width);
      pixel_y = map(x, TS_RT, TS_LEFT, 0, tft_height);
      break;
    case 2:      //PORTRAIT REV
      pixel_x = map(x, TS_RT, TS_LEFT, 0, tft_width);
      pixel_y = map(y, TS_BOT, TS_TOP, 0, tft_height);
      break;
    case 3:      //LANDSCAPE REV
      pixel_x = map(y, TS_BOT, TS_TOP, 0, tft_width);
      pixel_y = map(x, TS_LEFT, TS_RT, 0, tft_height);
      break;
  }
}

Adafruit_GFX_Button seven_btn, eight_btn, nine_btn, divide_btn, four_btn, five_btn, six_btn, times_btn, one_btn, two_btn, three_btn, minus_btn, clear_btn, zero_btn, equals_btn, plus_btn;

void setup()
{
  Serial.begin(9600);
  Serial.println("Calculator");
  tft.begin(0x9488);
  Touch_init();
  tft.setRotation(0);
  tft.fillScreen(BLACK);
  tft.fillRoundRect(0, 0, 320, 480, 40, CYAN);
  drawintro();
  //  delay(5000);
  tft.fillScreen(LIGHTGREY);
  seven_btn.initButton(&tft,  40, 165, 70, 70, BLACK, WHITE, BLACK, "7", 3);
  eight_btn.initButton(&tft,  120, 165, 70, 70, BLACK, WHITE, BLACK, "8", 3);
  nine_btn.initButton(&tft,  200, 165, 70, 70, BLACK, WHITE, BLACK, "9", 3);
  divide_btn.initButton(&tft,  280, 165, 70, 70, BLACK, BLUE, WHITE, "/", 3);
  four_btn.initButton(&tft,  40, 245, 70, 70, BLACK, WHITE, BLACK, "4", 3);
  five_btn.initButton(&tft,  120, 245, 70, 70, BLACK, WHITE, BLACK, "5", 3);
  six_btn.initButton(&tft,  200, 245, 70, 70, BLACK, WHITE, BLACK, "6", 3);
  times_btn.initButton(&tft,  280, 245, 70, 70, BLACK, BLUE, WHITE, "X", 3);
  one_btn.initButton(&tft,  40, 325, 70, 70, BLACK, WHITE, BLACK, "1", 3);
  two_btn.initButton(&tft,  120, 325, 70, 70, BLACK, WHITE, BLACK, "2", 3);
  three_btn.initButton(&tft,  200, 325, 70, 70, BLACK, WHITE, BLACK, "3", 3);
  minus_btn.initButton(&tft,  280, 325, 70, 70, BLACK, BLUE, WHITE, "-", 3);
  clear_btn.initButton(&tft,  40, 405, 70, 70, BLACK, RED, BLACK, "CE", 3);
  zero_btn.initButton(&tft,  120, 405, 70, 70, BLACK, WHITE, BLACK, "0", 3);
  equals_btn.initButton(&tft,  200, 405, 70, 70, BLACK, GREEN, BLACK, "=", 3);
  plus_btn.initButton(&tft,  280, 405, 70, 70, BLACK, BLUE, WHITE, "+", 3);
  seven_btn.drawButton(false);
  eight_btn.drawButton(false);
  nine_btn.drawButton(false);
  divide_btn.drawButton(false);
  four_btn.drawButton(false);
  five_btn.drawButton(false);
  six_btn.drawButton(false);
  times_btn.drawButton(false);
  one_btn.drawButton(false);
  two_btn.drawButton(false);
  three_btn.drawButton(false);
  minus_btn.drawButton(false);
  clear_btn.drawButton(false);
  zero_btn.drawButton(false);
  equals_btn.drawButton(false);
  plus_btn.drawButton(false);
  draw();
}

void loop() {
  tft.setCursor(25, 63);
  tft.setTextColor(BLACK);
  bool down = Touch_getXY();
  seven_btn.press(down && seven_btn.contains(pixel_x, pixel_y));
  eight_btn.press(down && eight_btn.contains(pixel_x, pixel_y));
  nine_btn.press(down && nine_btn.contains(pixel_x, pixel_y));
  divide_btn.press(down && divide_btn.contains(pixel_x, pixel_y));
  four_btn.press(down && four_btn.contains(pixel_x, pixel_y));
  five_btn.press(down && five_btn.contains(pixel_x, pixel_y));
  six_btn.press(down && six_btn.contains(pixel_x, pixel_y));
  times_btn.press(down && times_btn.contains(pixel_x, pixel_y));
  one_btn.press(down && one_btn.contains(pixel_x, pixel_y));
  two_btn.press(down && two_btn.contains(pixel_x, pixel_y));
  three_btn.press(down && three_btn.contains(pixel_x, pixel_y));
  minus_btn.press(down && minus_btn.contains(pixel_x, pixel_y));
  clear_btn.press(down && clear_btn.contains(pixel_x, pixel_y));
  zero_btn.press(down && zero_btn.contains(pixel_x, pixel_y));
  equals_btn.press(down && equals_btn.contains(pixel_x, pixel_y));
  plus_btn.press(down && plus_btn.contains(pixel_x, pixel_y));
  if (seven_btn.justPressed())
  {
    tft.print("7");
  }
  if (eight_btn.justPressed())
  {
    tft.print("8");
  }
  if (nine_btn.justPressed())
  {
    tft.print("9");
  }
  if (divide_btn.justPressed())
  {
    tft.print("/");
  }
  if (four_btn.justPressed())
  {
    tft.print("4");
  }
  if (five_btn.justPressed())
  {
    tft.print("5");
  }
  if (six_btn.justPressed())
  {
    tft.print("6");
  }
  if (times_btn.justPressed())
  {
    tft.print("x");
  }
  if (one_btn.justPressed())
  {
    tft.print("1");
  }
  if (two_btn.justPressed())
  {
    tft.print("2");
  }
  if (three_btn.justPressed())
  {
    tft.print("3");
  }
  if (minus_btn.justPressed())
  {
    tft.print("-");
  }
  if (clear_btn.justPressed())
  {
    tft.fillScreen(LIGHTGREY);
    draw();
    seven_btn.drawButton(false);
  eight_btn.drawButton(false);
  nine_btn.drawButton(false);
  divide_btn.drawButton(false);
  four_btn.drawButton(false);
  five_btn.drawButton(false);
  six_btn.drawButton(false);
  times_btn.drawButton(false);
  one_btn.drawButton(false);
  two_btn.drawButton(false);
  three_btn.drawButton(false);
  minus_btn.drawButton(false);
  clear_btn.drawButton(false);
  zero_btn.drawButton(false);
  equals_btn.drawButton(false);
  plus_btn.drawButton(false);
  }
  if (zero_btn.justPressed())
  {
    tft.print("0");
  }
  if (equals_btn.justPressed())
  {
    tft.print("=");
  }
  if (plus_btn.justPressed())
  {
    tft.print("+");
  }
}

void drawintro()
{
  tft.setTextSize(3);

  tft.setTextColor(BLUE);
  tft.setCursor(100, 100);
  tft.print("Arduino");
  tft.setCursor(75, 140);
  tft.setTextColor(YELLOW);
  tft.print("CALCULATOR");
  tft.setCursor(90, 250);
  tft.setTextColor(WHITE);
  tft.print("Touch To");
  tft.setCursor(90, 280);
  tft.print("Continue");
  tft.setCursor(100, 50);
  tft.fillRoundRect(62, 40, 200, 40, 8, YELLOW);
  tft.setTextColor(RED);
  tft.print("");
  tft.fillRoundRect(72, 215, 180, 5, 8, GREEN);
}

void draw()
{
  tft.fillRoundRect(5, 5, 310, 115, 8, WHITE);
  tft.drawRoundRect(5, 5, 310, 115, 8, BLACK);
}

If you know how to fix this, please enlighten me!

To confirm what you mean... if you press 4 then 2 say, it prints a 4, then replaces that with 2 to display only the 2, rather than displaying 42?

edit- if so, and yes that could be due to the setCursor() at the top of loop(), you could have a variable say "myCursorPos" which you increment each time you press a digit, and then use that variable in the setCursor().

@proton_aligner
No, it prints a unintelligible symbol, it does not erase the 4, but prints the 2 ON TOP OF the 4, while still displaying the four, displaying a 4 and a 2 on the same spot.

And what do you want it to do?- print 42 in two contiguouscells, or replace the 4 with the 2 to display a "nice" 2?

@proton_aligner
I want to print 42 in two contiguous cells.

Then try my idea of incrementing the position in the code.

(Disclaimer- I've never tried to use one of those screens)

@proton_aligner
That would be extremely complicated, but I'll try that if @david_prentice @6v6gt don't have any usable ideas.

What is a code example of doing that?

Why don't you try to implement it with the clues I gave in #2 ?

Off topic, but in all my years on various forums (or fora if you like) I don't think I've ever seen anyone addressing a thread to other members for their specific attention. Curious to know if that's acceptable netiquette?

image

I'm not sure, but I do it fairly often and no-one has complained yet, so I'm guessing no-one cares??

You can't just make up syntax like

image

I was thinking something along the lines of...

  • create a variable byte myCursor= 25 (or whichever of the 25 and 63 is the right one)
  • then where the digit is pressed do a myCursor++
  • and then setCursor(myCursor, 63) before doing the print.

@proton_aligner

myCursor = 25;
  tft.setCursor(myCursor, 63);
  tft.setTextColor(BLACK);
  bool down = Touch_getXY();
  seven_btn.press(down && seven_btn.contains(pixel_x, pixel_y));
  eight_btn.press(down && eight_btn.contains(pixel_x, pixel_y));
  nine_btn.press(down && nine_btn.contains(pixel_x, pixel_y));
  divide_btn.press(down && divide_btn.contains(pixel_x, pixel_y));
  four_btn.press(down && four_btn.contains(pixel_x, pixel_y));
  five_btn.press(down && five_btn.contains(pixel_x, pixel_y));
  six_btn.press(down && six_btn.contains(pixel_x, pixel_y));
  times_btn.press(down && times_btn.contains(pixel_x, pixel_y));
  one_btn.press(down && one_btn.contains(pixel_x, pixel_y));
  two_btn.press(down && two_btn.contains(pixel_x, pixel_y));
  three_btn.press(down && three_btn.contains(pixel_x, pixel_y));
  minus_btn.press(down && minus_btn.contains(pixel_x, pixel_y));
  clear_btn.press(down && clear_btn.contains(pixel_x, pixel_y));
  zero_btn.press(down && zero_btn.contains(pixel_x, pixel_y));
  equals_btn.press(down && equals_btn.contains(pixel_x, pixel_y));
  plus_btn.press(down && plus_btn.contains(pixel_x, pixel_y));
  if (seven_btn.justPressed())
  {
    tft.print("7");
  }
  if (eight_btn.justPressed())
  {
    myCursor = myCursor + 20;
    tft.setCursor(myCursor, 63);
    tft.print("8");
  }

This works. Until I want to start with a number other than 7...
:roll_eyes::roll_eyes::roll_eyes::thinking::thinking::thinking:

Define a character array which represents the calculator display area, say enough for 10 digits. Do all operations first in that array. For example, if the user has already entered 3 digits and enters another one, you put the next digit at the next free position in the array.
Each time there is an operation on that array, clean out a part of the screen and write the whole array out to that part of the screen. In practice, this will be a fixed area of the screen, say above the keypad. That is, don't attempt yourself to divide the screen into individual cells.

@6v6gt
I'm not sure I follow...
Are you saying the buttons should be an array, or the display of numbers?
How do I even do that?
Are there any examples of that kind of thing online?

It will help if you think through your project a little more.

Your calculator does not appear to have a button for a decimal point. Do you intend for it to work with whole numbers only? What result should it give when you try to divide 7 by 2 ?

What sort of variables will you use to hold the numbers? long? float? Or something else?

Which Arduino are you programming for? Some have the double datatype available (good for 15 or 16 digits), some don't.

The display of numbers should be defined as a character array say

char calc_display[ 11 ]  = { ' ' } ;  // 10 digit display blank filled including trailing /0

You have to maintain an index of the next free position in the display.
Initially, the index has a value of zero.

When the user hits say the key 4, a 4 is put into calc_display[ ] at the index position and the index is incremented in preparation for the next entry.
At the same time, the entire array is written to the display using the println() method or something similar. Say tft.println( calc_display ) .

This repeats until the user hits a command key such as '+', '-', '/', '*' etc.

You can test a lot of the logic without any display. Just use Serial.read() and Serial.print(). Get that right, then add the graphical part.

The top bar here, currently with a zero in it, would be represented by a character array.

@6v6gt

#include "Adafruit_GFX.h"    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#include <XPT2046_Touchscreen.h>           // Hardware SPI library
char *name = "Shield XPT2046 Calibration";  //edit name of shield
const int TS_LANDSCAPE = 1; //XPT2046_TouchScreen.h
const int TS_LEFT = 261, TS_RT = 3770, TS_TOP = 3869, TS_BOT = 296;
#define XPT_CS  53      // MEGA2560 SHIELD 
#define XPT_IRQ 255     // XPT2046 library does not like IRQ
XPT2046_Touchscreen ts(XPT_CS, XPT_IRQ);

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
  bool pressed = ts.touched();
  if (pressed) {
    TS_Point p = ts.getPoint();
    if (TS_LANDSCAPE) mapxy(p.y, p.x);
    else mapxy(p.x, p.y);
  }
  return pressed;
}

void Touch_init(void)
{
  ts.begin();
}

void mapxy(int x, int y)                //maps ADC to pixel_x, pixel_y
{
  int aspect = tft.getRotation();     //LANDSCAPE
  int tft_width = tft.width();
  int tft_height = tft.height();
  switch (aspect & 3) {
    case 0:      //PORTRAIT
      pixel_x = map(x, TS_LEFT, TS_RT, 0, tft_width);
      pixel_y = map(y, TS_TOP, TS_BOT, 0, tft_height);
      break;
    case 1:      //LANDSCAPE
      pixel_x = map(y, TS_TOP, TS_BOT, 0, tft_width);
      pixel_y = map(x, TS_RT, TS_LEFT, 0, tft_height);
      break;
    case 2:      //PORTRAIT REV
      pixel_x = map(x, TS_RT, TS_LEFT, 0, tft_width);
      pixel_y = map(y, TS_BOT, TS_TOP, 0, tft_height);
      break;
    case 3:      //LANDSCAPE REV
      pixel_x = map(y, TS_BOT, TS_TOP, 0, tft_width);
      pixel_y = map(x, TS_LEFT, TS_RT, 0, tft_height);
      break;
  }
}
#define YP A1 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 6 // can be a digital pin
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
/*_______End of defanitions______*/
/*______Assign names to colors and pressure_______*/
#define WHITE 0x0000 //Black->White
#define YELLOW 0x001F //Blue->Yellow
#define CYAN 0xF800 //Red->Cyan
#define PINK 0x07E0 //Green-> Pink
#define RED 0x07FF //Cyan -> Red
#define GREEN 0xF81F //Pink -> Green
#define BLUE 0xFFE0 //Yellow->Blue
#define BLACK 0xFFFF //White-> Black
#define MINPRESSURE 10
#define MAXPRESSURE 1000
/*_______Assigned______*/
/*____Calibrate TFT LCD_____*/
#define TS_MINX 125
#define TS_MINY 85
#define TS_MAXX 965
#define TS_MAXY 905
/*______End of Calibration______*/
String symbol[4][4] = {
  { "7", "8", "9", "/" },
  { "4", "5", "6", "*" },
  { "1", "2", "3", "-" },
  { "C", "0", "=", "+" }
};
int X, Y;
long Num1, Num2, Number;
char action;
boolean result = false;

void setup() {
  Serial.begin(9600); //Use serial monitor for debugging
  tft.reset(); //Always reset at start
  tft.begin(0x9488); // My LCD uses LIL9488 Interface driver IC
  Touch_init();
  tft.setRotation(2); // I just roated so that the power jack faces up - optional
  tft.fillScreen(WHITE);
  IntroScreen();

  draw_BoxNButtons();
}
void loop() {
  TS_Point p = waitTouch();
  X = p.y; Y = p.x;
  // Serial.print(X); Serial.print(','); Serial.println(Y);// + " " + Y);
  DetectButtons();
  if (result == true)
    CalculateResult();
  DisplayResult();
  delay(300);
}
TS_Point waitTouch() {
  TS_Point p;
  do {
    p = ts.getPoint();
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
  } while ((p.z < MINPRESSURE ) || (p.z > MAXPRESSURE));
  p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);
  p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);;
  return p;
}
void DetectButtons()
{

  if (X < 50 && X > 0) //Detecting Buttons on Column 1
  {
    if (Y > 0 && Y < 85) //If cancel Button is pressed
    {
      Serial.println ("Button Cancel");
      Number = Num1 = Num2 = 0;
      result = false;
    }

    if (Y > 85 && Y < 140) //If Button 1 is pressed
    { Serial.println ("Button 1");
      if (Number == 0)
        Number = 1;
      else
        Number = (Number * 10) + 1; //Pressed twice
    }

    if (Y > 140 && Y < 192) //If Button 4 is pressed
    { Serial.println ("Button 4");
      if (Number == 0)
        Number = 4;
      else
        Number = (Number * 10) + 4; //Pressed twice
    }

    if (Y > 192 && Y < 245) //If Button 7 is pressed
    { Serial.println ("Button 7");
      if (Number == 0)
        Number = 7;
      else
        Number = (Number * 10) + 7; //Pressed twice
    }
  }
  if (X < 105 && X > 50) //Detecting Buttons on Column 2
  {
    if (Y > 0 && Y < 85)
    { Serial.println ("Button 0"); //Button 0 is Pressed
      if (Number == 0)
        Number = 0;
      else
        Number = (Number * 10) + 0; //Pressed twice
    }

    if (Y > 85 && Y < 140)
    { Serial.println ("Button 2");
      if (Number == 0)
        Number = 2;
      else
        Number = (Number * 10) + 2; //Pressed twice
    }

    if (Y > 140 && Y < 192)
    { Serial.println ("Button 5");
      if (Number == 0)
        Number = 5;
      else
        Number = (Number * 10) + 5; //Pressed twic
    }

    if (Y > 192 && Y < 245)
    { Serial.println ("Button 8");
      if (Number == 0)
        Number = 8;
      else
        Number = (Number * 10) + 8; //Pressed twic
    }
  }
  if (X < 165 && X > 105) //Detecting Buttons on Column 3
  {
    if (Y > 0 && Y < 85)
    { Serial.println ("Button Equal");
      Num2 = Number;
      result = true;
    }

    if (Y > 85 && Y < 140)
    { Serial.println ("Button 3");
      if (Number == 0)
        Number = 3;
      else
        Number = (Number * 10) + 3; //Pressed twice
    }

    if (Y > 140 && Y < 192)
    { Serial.println ("Button 6");
      if (Number == 0)
        Number = 6;
      else
        Number = (Number * 10) + 6; //Pressed twice
    }

    if (Y > 192 && Y < 245)
    { Serial.println ("Button 9");
      if (Number == 0)
        Number = 9;
      else
        Number = (Number * 10) + 9; //Pressed twice
    }
  }
  if (X < 213 && X > 165) //Detecting Buttons on Column 3
  {
    Num1 = Number;
    Number = 0;
    tft.setCursor(200, 20);
    tft.setTextColor(RED);
    if (Y > 0 && Y < 85)
    {
      Serial.println ("Addition");
      action = 1;
      tft.println('+');
    }
    if (Y > 85 && Y < 140)
    {
      Serial.println ("Subtraction");
      action = 2;
      tft.println('-');
    }
    if (Y > 140 && Y < 192)
    {
      Serial.println ("Multiplication");
      action = 3;
      tft.println('*');
    }
    if (Y > 192 && Y < 245)
    {
      Serial.println ("Devesion");
      action = 4;
      tft.println('/');
    }
    delay(300);
  }
}
void CalculateResult()
{
  if (action == 1)
    Number = Num1 + Num2;
  if (action == 2)
    Number = Num1 - Num2;
  if (action == 3)
    Number = Num1 * Num2;
  if (action == 4)
    Number = Num1 / Num2;
}
void DisplayResult()
{
  tft.fillRect(0, 0, 240, 80, CYAN); //clear result box
  tft.setCursor(10, 20);
  tft.setTextSize(4);
  tft.setTextColor(BLACK);
  tft.println(Number); //update new value
}
void IntroScreen()
{
  tft.setCursor (55, 120);
  tft.setTextSize (3);
  tft.setTextColor(RED);
  tft.println("ARDUINO");
  tft.setCursor (30, 160);
  tft.println("CALCULATOR");
  tft.setCursor (30, 220);
  tft.setTextSize (2);
  tft.setTextColor(BLUE);
  tft.println("-Circut Digest");
  delay(1800);
}
void draw_BoxNButtons()
{
  //Draw the Result Box
  tft.fillRect(0, 0, 240, 80, CYAN);
  //Draw First Column
  tft.fillRect (0, 260, 60, 60, RED);
  tft.fillRect (0, 200, 60, 60, BLACK);
  tft.fillRect (0, 140, 60, 60, BLACK);
  tft.fillRect (0, 80, 60, 60, BLACK);
  //Draw Third Column
  tft.fillRect (120, 260, 60, 60, GREEN);
  tft.fillRect (120, 200, 60, 60, BLACK);
  tft.fillRect (120, 140, 60, 60, BLACK);
  tft.fillRect (120, 80, 60, 60, BLACK);
  //Draw Secound & Fourth Column
  for (int b = 260; b >= 80; b -= 60)
  { tft.fillRect (180, b, 60, 60, BLUE);
    tft.fillRect (60, b, 60, 60, BLACK);
  }
  //Draw Horizontal Lines
  for (int h = 80; h <= 320; h += 60)
    tft.drawFastHLine(0, h, 240, WHITE);
  //Draw Vertical Lines
  for (int v = 0; v <= 240; v += 60)
    tft.drawFastVLine(v, 80, 240, WHITE);
  //Display keypad lables
  for (int j = 0; j < 4; j++) {
    for (int i = 0; i < 4; i++) {
      tft.setCursor(22 + (60 * i), 100 + (60 * j));
      tft.setTextSize(3);
      tft.setTextColor(WHITE);
      tft.println(symbol[j][i]);
    }
  }
}

I have found this code which I originally thought I could use, but after changing it for my screen, it don't work.
It displays things, but the touch does not work.
Original code:

I think it does the same sort of thing you are talking about

He is doing it using another but similar method.
He is collecting what the user types using the variable Number :

long Num1, Num2, Number;
. . .
. . .
//button 6 hit:

   if (Y > 140 && Y < 192)
    { Serial.println ("Button 6");
      if (Number == 0)
        Number = 6;
      else
        Number = (Number * 10) + 6; //Pressed twice
    }
. . .
. . .
// number displayed
tft.println(Number); //update new value

I don't immediately see how this handles the decimal point as also pointed out by @odometer

@6v6gt
I have no idea how the decimal point works, that's another issue in itself.
I want to have a decimal point, but I'll get this working before I add more complexities, unless it's easier to implement it at the same time?
Does anyone know how to fix the touch screen side of the issue?
I've tried a few different things, but none of them work.