/**
First demo for FT6206 Capactive Touch Screen on Wokwi. Enjoy!
https://wokwi.com/arduino/projects/311598148845830720
*/
/***************************************************
This is our touchscreen painting example for the Adafruit ILI9341
captouch shield
----> http://www.adafruit.com/products/1947
Check out the links above for our tutorials and wiring diagrams
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.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
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup(void) {
while (!Serial); // used for leonardo debugging
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
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);
}
void loop() {
delay(10);
swipe_RL();
// Wait for a touch
/* if (! ctp.touched()) {
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(" -> ");
*/
/*if (ctp.touched()) {
// flip it around to match the screen.
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
Serial.println(p.x);
//Serial.println(p.y);
}*/
}
byte swipe_RL() {
TS_Point p;
uint8_t x_touch;
static bool swipe_flag = false;
static uint8_t start_touch;
static uint8_t end_touch;
static unsigned long startMillis = 0;
if(ctp.touched()) {
p = ctp.getPoint();
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
x_touch = p.x;
}
if(!swipe_flag && ctp.touched()) {
startMillis = millis();
swipe_flag = true;
start_touch = x_touch;
//Serial.print("start_touch:");
//Serial.println(start_touch);
}
if (!ctp.touched()) {
end_touch = x_touch;
if(swipe_flag) {
//Serial.print("end_touch:");
//Serial.println(end_touch);
bool cmp_R = start_touch < end_touch;
bool cmp_L = start_touch > end_touch;
bool min_len = abs((start_touch - end_touch)) > 10;
if(cmp_R && min_len) {
start_touch = NULL;
end_touch = NULL;
swipe_flag = false;
Serial.println("swipe right");
return 1;
}
if(cmp_L && min_len) {
start_touch = NULL;
end_touch = NULL;
swipe_flag = false;
Serial.println("swipe left");
return 2;
}
startMillis = millis();
}
swipe_flag = false;
return 0;
}
if((millis() - startMillis) > 2000) {
start_touch = NULL;
end_touch = NULL;
swipe_flag = false;
startMillis = millis();
}
}
Loading
ili9341-cap-touch
ili9341-cap-touch