#include <Adafruit_GFX.h>
#include <Adafruit_FT6206.h>
#include <Adafruit_ILI9341.h>
//Defining the pins that aren't Hardware SPI.
const int SPI_PIN_CS = 9;
const int PIN_DC = 7;
const int PIN_RST = 8;
//Defining spaces for the colors so as to use a value than can be changed
static byte X_SPACE = 40;
static byte Y_SPACE = 40;
#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 TS_MINX 0
#define TS_MINY 0
#define TS_MAXX 240
#define TS_MAXY 320
//Creating an object called "tft" that can be called by any of the functions in the Adafruit_GFX and
//Adafruit ILI9341 Libraries. Because the ILI9341 Cap Touch uses SPI, the hardware pins can be used
//for better and more reliable preformance
Adafruit_ILI9341 tft = Adafruit_ILI9341(SPI_PIN_CS, PIN_DC, PIN_SPI_MOSI, PIN_SPI_SCK, PIN_RST, PIN_SPI_MISO);
//Creating an object called "ts". Because the Capacitive Touch is I2C, nothing is defined here, but
//SDA and SCL must be properly connected or it will not work at all.
Adafruit_FT6206 ts = Adafruit_FT6206();
#define BOXSIZE 40
#define PENRADIUS 3
#define MINPRESSURE 10
#define MAXPRESSURE 1000
int touch = 0;
void setup() {
Serial.begin(9600);
tft.begin();
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.fillScreen(BLACK);
tft.fillRect(0, 0, 120, 120, GREEN);
tft.fillRect(120, 0, 120, 120, RED);
tft.setCursor(8, 45);
tft.println("LED ON");
tft.setCursor(128, 45);
tft.println("LEDOFF");
tft.begin();
if(!ts.begin(40)){
while(1);
return;
}
}
void loop() {
if(!ts.touched()){
delay(10);
return;
}
TS_Point p = ts.getPoint();
//if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
if (p.x>0 && p.x<120) (p.y>0 && p.y<120); {
digitalWrite(10, HIGH);
touch = 0;
delay(2000);
}
if (p.x>=120 && p.x<=240); {
digitalWrite(10, LOW);
touch = 0;
delay(200);
}
}