1.8" TFT Color Display ST7735 128x160 modifications

Hi, so recently I have been using the display mentioned in the title to measure rpm from my motor. The problem is the display only shows 3 digits. When the motor goes beyond 1000s it displays it as 100s. I was wondering if I could modify the code somehow to make it display 4 digits instead of only 3. I am using the code below.

Thanks

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8

// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char sensorPrintout[4];

void setup() {

  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);

  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255, 255, 255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Sensor Value :\n ", 0, 0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(5);
}

void loop() {

  // Read the value of the sensor on A0
  String sensorVal = String(analogRead(A0));

  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);

  // set the font color
  TFTscreen.stroke(255, 255, 255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(sensorPrintout, 0, 20);
}

Do you need to reduce the text size?

TFTscreen.setTextSize(5);

I tried changing that but it came up the same. I will post my whole code below if maybe there is a limitation in the code to screen transfer. I find it quite strange this screen can only display 3 digits when even at biggest text size there seems to be room for at least 6 or 7 digits onscreen.

int switchPinFwd = 7;     //Input from the switch when in the Forward position
int potentiometerIn;      //variable to hold the potentiometer input

int fwdPin = 3;           //Logic level output to the H-Bridge (Forward)
int revPin = 4;           //Another logic level output to the H-Bridge (Reverse)
#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8

// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char sensorPrintout[4];
int hallsensor = 2;                // Hall sensor at pin 2

volatile byte counter;

unsigned int rpm;

unsigned long passedtime;

void isr()

 {

   //Each rotation, this interrupt function is run twice, so take that into consideration for

   //calculating RPM

   //Update count

      counter++;

 }
void setup()

 {  // put your setup code here, to run once:
  pinMode(switchPinFwd, INPUT_PULLUP);

  pinMode(fwdPin, OUTPUT); //Set the forward pin to an output
  pinMode(revPin, OUTPUT); //Set the forward pin to an output
  Serial.begin(9600);

   //Intiates Serial communications

   attachInterrupt(0, isr, RISING); //Interrupts are called on Rise of Input

   pinMode(hallsensor, INPUT); //Sets hallsensor as input

   counter = 0;

   rpm = 0;

   passedtime = 0; //Initialise the values
   
   // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);

  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255, 255, 255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("RPM :\n ", 0, 0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(2);

 }
 void loop()
 { // put your main code here, to run repeatedly:
  potentiometerIn = analogRead(A0);
  int output = potentiometerIn / 4; //divide the potentiometer input by 4 so it can be used in the AnalogWrite function

  if(digitalRead(switchPinFwd) == HIGH) //Check to see if the pin is high or low
  {
    //If the pin is HIGH, it must be set to forward
      analogWrite(fwdPin, output); //Output our potentiometer value on the forward pin.
  }
  else
  {
    //Otherwise the switch must be set to Reverse
    analogWrite(revPin, output); //Output our potentiometer value on the forward pin.
  }
  delay(25);
   delay(999);//Update RPM every second
   

   detachInterrupt(0); //Interrupts are disabled

   rpm= 30*1000/ (millis() - passedtime)*counter;    


   passedtime = millis();

   counter = 0;

   Serial.print("RPM=");
   
   Serial.println(rpm); //Pri-nt out result to monitor

   
   attachInterrupt(0, isr, RISING);   //Restart the interrupt processing

    // Read the value of the sensor on A0
  String sensorVal = String((rpm));

  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);

  // set the font color
  TFTscreen.stroke(255, 255, 255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(sensorPrintout, 0, 20);
     
      }
String sensorVal = String((rpm));

  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);

The last argument of the toCharArray() function is the length of the receiving array. 4 is 3 characters plus a null terminator. You could increase the length argument value or better, in my opinion,

those lines can be replaced with

itoa(rpm, sensorPrintout, 10);

itoa() reference.

The use of
Strings is to be discouraged. See the evils of strings page.