#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>
// 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);
#define BUTTON_A 16
#define BUTTON_B 17
#define BUTTON_C 18
TS_Point p_current;
TS_Point p_prev;
void IRAM_ATRR A_Pulsado() {
Apulsado = true;
}
void IRAM_ATRR B_Pulsado() {
Bpulsado = true;
}
void IRAM_ATRR C_Pulsado() {
Cpulsado = true;
}
void setup() {
//while (!Serial); // used for leonardo debugging
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
Wire.setPins(10, 8); // redefine first I2C port to be on pins 10/8
tft.begin();
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(ILI9341_BLACK);
tft.setRotation(2);
pinMode(BUTTON_A, INPUT_PULLUP);
pinMode(BUTTON_B, INPUT_PULLUP);
pinMode(BUTTON_C, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON_A), A_Pulsado, RISING);
attachInterrupt(digitalPinToInterrupt(BUTTON_B), B_Pulsado, RISING);
attachInterrupt(digitalPinToInterrupt(BUTTON_C), C_Pulsado, RISING);
}
void loop() {
switch (state) {
case 0:
break;
case 1:
// Wait for a touch
if (ctp.touched()) {
p_current = ctp.getPoint();
if (p_current != p_prev) {
Serial.printf("x:%d, y:%d \r\n", p_current.x, p_current.y);
tft.drawPixel(p_current.x, p_current.y, ILI9341_WHITE);
}
p_prev = p_current;
}
case 2
}
delay(10);
}