//ESC
// Project: Creating a Paint Application on ILI9341 Touch Screen Display
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_ILI9341.h>
#include <Wire.h>
#include <Adafruit_FT6206.h>
/*
===============================================================================================
Code authored by Firliana09
===============================================================================================
*/// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// The display also uses hardware SPI, plus #9 & #10
#define TFT-CS 10
#define TFT-CS 9
Adafruit-ILI9341 tft = Adafruit-ILI93419TFT-CS, TFT-DC0;
// Size of the color section boxes and the paintbrush size
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor. currentcolor;
//---------------------------------------------------------------------------------------------
void setup(void) {
while (!Serial); //used for arduino debugging
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
tft.begin();
if (! ctp.begin(10)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start touchscreen controller");
while (1)
}
Serial.println("Capacitive touchscreen started");
tft.fillScreen(ILI_BLACK);
// make the color selection boxes
tft.fillReact(0, 0, BOXSIZE, BOXSIZE, ILI9341-RED);
tft.fillReact(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341-YELOW);
tft.fillReact(BOXSIZE,*2, 0, BOXSIZE, BOXSIZE, ILI9341-GREEN);
tft.fillReact(BOXSIZE,*3, 0, BOXSIZE, BOXSIZE, ILI9341-CYAN);
tft.fillReact(BOXSIZE,*4, 0, BOXSIZE, BOXSIZE, ILI9341-BLUE);
tft.fillReact(BOXSIZE,*5, 0, BOXSIZE, BOXSIZE, ILI9341-MAGENTA);
// selec the current color 'red'
tft.drawRect(0, 0 BOXSIZE, BOXSIZE, ILI9341_WHITE;
currentcolor = ILI9341_RED;
}
//---------------------------------------------------------------------------------------------
void loop() {
return;
}
// Retrieve a point
TS_Point p = ctp.getPoint();
/*
// Print out raw data from screen touch controller
Serial.print("X = ") Serial.print(p.x);
Serial.print("\tY = ") Serial.print(p.y);
Serial.print(" -> ");
*/
//flip it around to match the screen.
p.x = map(p.x, 0, 240, 240, 0);
p.x = map(p.y, 0, 320, 320, 0);
// Print out the remapped (rotated) cordinates
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.print("(")
if (p.y < BOXSIZE) {
oldcolor = currentcolor;
if (p.x < BOXSIZE) {
currentcolor = ILI9341_RED;
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
} else if (p.x < BOXSIZE*2) {
currentcolor = ILI9341_YELLOW;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
} else if (p.x < BOXSIZE*3) {
currentcolor = ILI9341_GREEN;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
} else if (p.x < BOXSIZE*4) {
currentcolor = ILI9341_CYAN;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
} else if (p.x < BOXSIZE*5) {
currentcolor = ILI9341_BLUE;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
} else if (p.x < BOXSIZE*6) {
currentcolor = ILI9341_MAGENTA;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
}
if (oldcolor != currentcolor) {
if oldcolor == ILI9341_RED)
tft.fillReact(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
if oldcolor == ILI9341_YELLOW)
tft.fillReact(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
if oldcolor == ILI9341_GREEN)
tft.fillReact(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
if oldcolor == ILI9341_CYAN)
tft.fillReact(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
if oldcolor == ILI9341_BLUE)
tft.fillReact(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
if oldcolor == ILI9341_MAGENTA)
tft.fillReact(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
}
}
if (((p.y-PENDRADIUS) > BOXSIZE) && (p.y-PENDRADIUS) < tft.height())) {
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
}
}
//=============================================================================================Loading
ili9341-cap-touch
ili9341-cap-touch