Please see my code below. I must say its for a STM32 blue pill but i wouldn't think that should matter would it?
I'v had to delete some of the functions as it exceeded the 9000 limit
#include "XPT2046_touch.h"
#include "SPI.h"
#include <Adafruit_GFX_AS.h> // Core graphics library, with extra fonts.
#include <Adafruit_ILI9341_STM.h> // STM32 DMA Hardware-specific library
#include <FreeMonoBold9pt7b.h>
#include <FreeMonoBold12pt7b.h>
#include <FreeMonoBold18pt7b.h>
#include <FreeMonoBold24pt7b.h>
// For the Adafruit shield, these are the default.
#define TFT_CS PA0
#define TFT_DC PA1
#define TFT_RST PA2
#define CS_PIN PA4 // Chip Select pin
char currentPage;
uint16_t xy[2];
int px = xy[0];
int py = xy[1];
byte SB = 0;
byte BO = 0;
SPIClass mySPI(2); //Create an SPI instance on SPI1 port.
XPT2046_touch ts(CS_PIN, mySPI); // Chip Select pin, SPI port
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_RST); // Use hardware SPI
void setup() {
Serial.begin(115200);
tft.begin();
ts.begin(); //Begin TouchScreen.
tft.fillScreen(ILI9341_BLACK);
tft.setRotation(1);
currentPage = '0';
//drawSpringBack();
drawhomeScreen();
//settingsScreen();
}
void loop(void) {
if (currentPage == '0') {
if(ts.read_XY(xy)){
getXY();
//Serial.print("x=");
// Serial.println(px);
//Serial.print("y=");
//Serial.println(py);
if ((px>=20) && (px<=300) && (py>=100) && (py<=150)) {
currentPage = '1';
tft.fillScreen(ILI9341_BLACK);
settingsScreen();
}
/*if ((x>=35) && (x<=285) && (y>=140) && (y<=180)) {
drawFrame(35, 140, 285, 180);
currentPage = '2';
myGLCD.clrScr();
drawLedControl();*/
}
}
if (currentPage == '1') {
if(ts.read_XY(xy)){
getXY();
if ((px>=20) && (px<=150) && (py>=190) && (py<=210)) {
currentPage = '0';
tft.fillScreen(ILI9341_BLACK);
drawhomeScreen();
}
if ((px>=20) && (px<=300) && (py>=10) && (py<=80)) {
currentPage = '2';
tft.fillScreen(ILI9341_BLACK);
drawSpringBack();
}
if ((px>=20) && (px<=300) && (py>=100) && (py<=150)) {
currentPage = '3';
tft.fillScreen(ILI9341_BLACK);
drawBackOff();
}
}
}
if (currentPage == '2') {
if(ts.read_XY(xy)){
getXY();
if ((px>=240) && (px<=300) && (py>=100) && (py<=150)) {
Serial.print("x=");
Serial.println(px);
Serial.print("y=");
Serial.println(py);
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_BLACK);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(SB);
SB++;
if (SB > 15){
SB = 0;
}
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(SB);
delay(300);
}
if ((px>=240) && (px<=300) && (py>=170) && (py<=220)) {
Serial.print("x=");
Serial.println(px);
Serial.print("y=");
Serial.println(py);
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_BLACK);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(SB);
SB--;
if (SB > 15){
SB = 15;
}
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(SB);
delay(300);
}
if ((px>=20) && (px<=80) && (py>=100) && (py<=220)) {
currentPage = '1';
tft.fillScreen(ILI9341_BLACK);
settingsScreen();
}
}
}
if (currentPage == '3') {
if(ts.read_XY(xy)){
getXY();
if ((px>=240) && (px<=300) && (py>=100) && (py<=150)) {
//Serial.print("x=");
//Serial.println(px);
//Serial.print("y=");
//Serial.println(py);
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_BLACK);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(BO);
BO++;
if (BO > 25){
BO = 0;
}
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(BO);
delay(300);
}
if ((px>=240) && (px<=300) && (py>=170) && (py<=220)) {
// Serial.print("x=");
//Serial.println(px);
//Serial.print("y=");
//Serial.println(py);
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_BLACK);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(BO);
BO--;
if (BO > 25){
BO = 25;
}
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(BO);
delay(300);
}
if ((px>=20) && (px<=80) && (py>=100) && (py<=220)) {
currentPage = '1';
tft.fillScreen(ILI9341_BLACK);
settingsScreen();
}
}
}
}
void settingsScreen(){ //Screen "1"
tft.fillRoundRect(20, 10, 280, 70, 20, ILI9341_RED);
tft.setCursor(40, 50);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold18pt7b);
tft.setTextSize(1);
tft.println("SPRING BACK");
tft.fillRoundRect(20, 100, 280, 70, 20, ILI9341_RED);
tft.setCursor(47, 147);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(1);
tft.println("BACK-OFF");
tft.fillRoundRect(20, 190, 130, 50, 20, ILI9341_RED);
tft.setCursor(65, 225);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(1);
tft.println("<");
}
void drawSpringBack(){
tft.setCursor(10, 10);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold9pt7b);
tft.println("This setting bends pipe over");
tft.setCursor(10, 25);
tft.println("the desired bend angle to");
tft.setCursor(10, 40);
tft.println("compensate for spring back");
tft.setCursor(10, 55);
tft.println("of the pipe, select an angle");
tft.setCursor(10, 70);
tft.println("after trial run");
tft.fillRoundRect(240, 100, 60, 50, 10, ILI9341_RED);
tft.setCursor(255, 135);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.println("+");
tft.fillRoundRect(240, 170, 60, 50, 10, ILI9341_RED);
tft.setCursor(255, 205);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.println("-");
tft.fillRoundRect(20, 100, 60, 120, 10, ILI9341_RED);
tft.setCursor(35, 170);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.println("<");
tft.setCursor(100, 195);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextSize(2);
tft.println(SB);
}