#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#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 122
#define TS_MINY 111
#define TS_MAXX 942
#define TS_MAXY 890
#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
#define MINPRESSURE 10
#define MAXPRESSURE 1000
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int page = 0;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);
boolean buttonEnabled = true;
void setup() {
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(0x7575);
tft.setRotation(1);
tft.fillScreen(YELLOW);
tft.drawRect(0, 0, 240, 320, YELLOW);
tft.fillRect(10, 10, 280, 50, RED);
tft.drawRect(10, 10, 280, 50, BLACK);
tft.setCursor(20, 15);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("A");
tft.fillRect(10, 150, 280, 50, GREEN);
tft.drawRect(10, 150, 280, 50, BLACK);
tft.setCursor(20, 155);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("B");
}
void loop() {
TSPoint p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE ) {
p.x = map(p.x, TS_MAXX, TS_MINX, tft.width(), 0);
p.y = map(p.y, TS_MAXY, TS_MINY, tft.height(), 0);
if (p.x > 10 && p.x < 60 && p.y > 10 && p.y < 290 && buttonEnabled) {
if (page == 2) {
buttonEnabled = false;
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillRect(10, 10, 280, 50, BLUE);
tft.drawRect(10, 10, 280, 50, BLACK);
tft.setCursor(20, 15);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("C");
}
if (page == 1) {
tft.fillRect(10, 10, 280, 50, RED);
tft.drawRect(10, 10, 280, 50, BLACK);
tft.setCursor(20, 15);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("1");
tft.fillRect(10, 150, 280, 50, RED);
tft.drawRect(10, 150, 280, 50, BLACK);
tft.setCursor(20, 155);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("2");
}
TSPoint p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE ) {
p.x = map(p.x, TS_MAXX, TS_MINX, tft.width(), 0);
p.y = map(p.y, TS_MAXY, TS_MINY, tft.height(), 0);
if (p.x > 180 && p.x < 230 && p.y > 10 && p.y < 290 && buttonEnabled) {
if ( page == 2) {
buttonEnabled = false;
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillRect(10, 10, 280, 50, GREEN);
tft.drawRect(10, 10, 280, 50, BLACK);
tft.setCursor(20, 15);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("3");
tft.fillRect(10, 150, 280, 50, GREEN);
tft.drawRect(10, 150, 280, 50, BLACK);
tft.setCursor(20, 155);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("4");
}
if ( page == 1) {
buttonEnabled = false;
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillRect(10, 10, 280, 50, GREEN);
tft.drawRect(10, 10, 280, 50, BLACK);
tft.setCursor(20, 15);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("Z");
tft.fillRect(10, 150, 280, 50, GREEN);
tft.drawRect(10, 150, 280, 50, BLACK);
tft.setCursor(20, 155);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.print("Y");
}
if (page == 0) {
page = 1;
}
}
}
}
}
}