Hi guys, forgive me if this is a simple problem,
I’m trying to create an interface with buttons leading to various pages, I’ve fallen at the first hurdle and the location of my button isn’t playing ball with where I’ve located it, I even added a rectangle of the required coordinates after the press to show where the region was,
so in a nutshell I have a button at the bottom of the screen and it only moves to the next page when I press around the left of the screen, I have no idea why it’s not working as I’ve followed numerous tutorials on this and my code looks no different to everyone else’s, please see attached,
EDIT: I think it’s a rotation problem as it seems the ‘imaginary’ button it’s using is rotated 90 degrees on the left side, not sure what the correction to this is however
#include <Elegoo_GFX.h> // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define TS_MINX 123
#define TS_MINY 133
#define TS_MAXX 938
#define TS_MAXY 880
#define YP A3
#define XM A2
#define YM 9
#define XP 8
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);
boolean buttonEnabled = true;
int CurrentPage = 0;
void DrawHome()
{
CurrentPage == 0;
tft.fillScreen(WHITE);
tft.drawRect(0,0,320,240,BLACK);
tft.setCursor(30,40);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print(" Automatic Drilling");
tft.setCursor(30,80);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print(" Press Start to Begin");
tft.fillRect(105,180, 95, 40, RED);
tft.drawRect(105,180,95,40,BLACK);
tft.setCursor(120,190);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Start");
}
void setup()
{
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(0x9341);
tft.setRotation(1);
DrawHome();
}
void loop() {
TSPoint p = ts.getPoint();
if (CurrentPage == 0);
{
/* if (p.z > 100) {*/
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
if(p.x>106 && p.x<202 && p.y>187 && p.y<227 /*&& buttonEnabled */){
// buttonEnabled = false;
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillScreen(WHITE);
tft.drawRect(0,0,320,240,YELLOW);
tft.drawRect(106, 187, 96, 40, BLACK);
/*tft.setCursor(50,70);
tft.setTextColor(BLACK);
tft.setTextSize(3);
tft.print(" Test");*/
}
}
}