#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Arduino.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
#include <GuiInput.h>
// 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_DC 9
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
GuiInput* gi = new GuiInput(&tft);
// Size of the color selection boxes and the paintbrush size
#define BOXSIZE 40
#define PENRADIUS 3
#define TFT_REDARK 0x60C3
#define TFT_RED2 0xA0C3
#define TFT_GRAY 0x738E
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
word convertRGB( byte R, byte G, byte B)
{
return ( ((R & 0xF8) << 8) | ((G & 0xFC) << 3) | (B >> 3) );
}
void setup(void) {
//while (!Serial); // used for leonardo debugging
Serial.begin(115200);
Wire.setPins(10, 8); // redefine first I2C port to be on pins 10/8
tft.begin();
tft.setRotation(1);
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
Serial.println("Capacitive touchscreen started");
tft.fillScreen(convertRGB(168, 141, 50));
gi->draw(10,10);
}
void loop() {
// Wait for a touch
if (! ctp.touched()) {
return;
}
// Retrieve a point
TS_Point p = ctp.getPoint();
// flip it around to match the screen.
// p.x = map(p.x, 0, 320, 0, 0);
// p.y = map(p.y, 0, 240, 240, 0);
// Print out raw data from screen touch controller
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print(" -> ");
gi->click(p.x, p.y);
}