print encoder position on tft display

how can I print the encoder position on tft display?

I can get position 9 but it all goes to mush if I try anything else

/*******Interrupt-based Rotary Encoder Sketch*******
by Simon Merrett, based on insight from Oleg Mazurov, Nick Gammon, rt, Steve Spence
*/

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

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

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



static int pinA = 2; // Our first hardware interrupt pin is digital pin 2
static int pinB = 3; // Our second hardware interrupt pin is digital pin 3
volatile byte aFlag = 0; // let's us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent
volatile byte bFlag = 0; // let's us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)
volatile byte encoderPos = 0; //this variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
volatile byte oldEncPos = 0; //stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)
volatile byte reading = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
// Button reading, including debounce without delay function declarations
const byte buttonPin = 4; // this is the Arduino pin we are connecting the push button to
byte oldButtonState = HIGH;  // assume switch open because of pull-up resistor
const unsigned long debounceTime = 10;  // milliseconds
unsigned long buttonPressTime;  // when the switch last changed state
boolean buttonPressed = 0; // a flag variable

void setup() {
  pinMode(pinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
  pinMode(pinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
  attachInterrupt(0,PinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
  attachInterrupt(1,PinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
  Serial.begin(115200); // start the serial monitor link
    // button section of setup
  pinMode (buttonPin, INPUT_PULLUP); // setup the button pin

    // 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("Welcome!", 00, 0);


  
}

void PinA(){
  cli(); //stop interrupts happening before we read pin values
  reading = PIND & 0xC; // read all eight pin values then strip away all but pinA and pinB's values
  if(reading == B00001100 && aFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
    encoderPos --; //decrement the encoder's position count
    if(encoderPos >200) {encoderPos =23; }  //0-23 (24 positions)
    bFlag = 0; //reset flags for the next turn
    aFlag = 0; //reset flags for the next turn
  }
  else if (reading == B00000100) bFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
  sei(); //restart interrupts
}

void PinB(){
  cli(); //stop interrupts happening before we read pin values
  reading = PIND & 0xC; //read all eight pin values then strip away all but pinA and pinB's values
  if (reading == B00001100 && bFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
    encoderPos ++; //increment the encoder's position count
    if(encoderPos >23) {encoderPos =0; }  //0-23 (24 positions)
    bFlag = 0; //reset flags for the next turn
    aFlag = 0; //reset flags for the next turn
  }
  else if (reading == B00001000) aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
  sei(); //restart interrupts
}



void loop(){

  if(oldEncPos != encoderPos) {
    Serial.println(encoderPos);    
    oldEncPos = encoderPos;// DEBUGGING


  
  if(encoderPos ==9)
    TFTscreen.stroke(255, 255, 255);
  // set the font size
  TFTscreen.setTextSize(3);
  TFTscreen.text("9", 50, 50);
  }
  else {
 TFTscreen.stroke(0, 0, 0);
 TFTscreen.text(" ", 0, 40);

 
  
  }// DEBUGGING
  // Button reading with non-delay() debounce - thank you Nick Gammon!
  byte buttonState = digitalRead (buttonPin); 
  if (buttonState != oldButtonState){
    if (millis () - buttonPressTime >= debounceTime){ // debounce
      buttonPressTime = millis ();  // when we closed the switch 
      oldButtonState =  buttonState;  // remember for next time 
      
      if (buttonState == LOW){
        Serial.println ("Button Pressed"); // DEBUGGING: print that button has been closed
        buttonPressed = 1;
   
      
  // set the font color to green
  TFTscreen.stroke(38, 255, 0);
  // set the font size
  TFTscreen.setTextSize(1);
  // write the text to the top left corner of the screen
  TFTscreen.text("Button Pressed", 0, 40);

      }
      else {
        Serial.println ("Button Released"); // DEBUGGING: print that button has been opened
        buttonPressed = 0; 

 TFTscreen.stroke(0, 0, 0);
 TFTscreen.text("Button Pressed", 0, 40); 



  
      }  
    }  // end if debounce time up
  } // end of state change
  }

I'd start by renaming your ISR functions - PinA() and PinB(). Very confusing since you also have variables pinA and pinB. It took me a second to realize that. Maybe PinAISR()?

Inside those ISR, interrupts are already off so no need to cli() and sei(). That is handled automatically.

Have you look into the Encoder library? It does all this for you..

Inside your loop(), if the encoder hasn't changed, you call

  else {
    TFTscreen.stroke(0, 0, 0);
    TFTscreen.text(" ", 0, 40);



  }

which will execute every time through loop() which seems like a waste.

I put that there to try to overwrite the previous number otherwise it stays on the screen when I turn the encoder,

The original sketch works perfectly without changing anything, but it prints to the serial monitor when I want it on the tft screen

I figured it out myself, I used case statements