/**
ESP32s3 adaptation by Tyeth Gundry of Arduino version of
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 <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);
// Size of the color selection boxes and the paintbrush size
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;
void setup(void) {
//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);
// make the color selection boxes
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
// select the current color 'red'
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
currentcolor = ILI9341_RED;
}
void loop() {
delay(10);
// Wait for a touch
if (! ctp.touched()) {
return;
}
}
#include "FS.h"
#include <SPI.h>
#include <TFT_eSPI.h>
#include <SvgParser.h>
#include "SvgOutput_TFT_eSPI.h"
TFT_eSPI tft = TFT_eSPI();
SvgOutput_TFT_eSPI svgOutput = SvgOutput_TFT_eSPI();
SvgParser svg = SvgParser(&svgOutput);
#define CALIBRATION_FILE "/calibrationData"
int counter = 42;
char * increment(int argc, char* argv[]) {
counter++;
return NULL;
}
char * decrement(int argc, char* argv[]) {
counter--;
return NULL;
}
char * printCounter(int argc, char* argv[]) {
char *ptr = (char *)malloc(10);
if (ptr == NULL) return NULL;
sprintf(ptr, "%i", counter);
return ptr;
}
char * printTime(int argc, char* argv[]) {
char *ptr = (char *)malloc(10);
if (ptr == NULL) return NULL;
sprintf(ptr, "%i", millis());
return ptr;
}
void setup2(void) {
uint16_t calibrationData[5];
uint8_t calDataOK = 0;
Serial.begin(115200);
Serial.println("starting");
tft.init();
tft.setRotation(2);
tft.fillScreen((0xFFFF));
tft.setCursor(20, 0, 2);
tft.setTextColor(TFT_BLACK, TFT_WHITE); tft.setTextSize(1);
tft.println("calibration run");
// check file system
if (!SPIFFS.begin()) {
Serial.println("formating file system");
SPIFFS.format();
SPIFFS.begin();
}
// check if calibration file exists
if (SPIFFS.exists(CALIBRATION_FILE)) {
File f = SPIFFS.open(CALIBRATION_FILE, "r");
if (f) {
if (f.readBytes((char *)calibrationData, 14) == 14)
calDataOK = 1;
f.close();
}
}
if (calDataOK) {
// calibration data valid
calibrationData[4] ^= 0x06;
tft.setTouch(calibrationData);
} else {
// data not valid. recalibrate
tft.calibrateTouch(calibrationData, TFT_WHITE, TFT_RED, 15);
calibrationData[4] ^= 0x06;
tft.setTouch(calibrationData);
// store data
File f = SPIFFS.open(CALIBRATION_FILE, "w");
if (f) {
f.write((const unsigned char *)calibrationData, 14);
f.close();
}
}
tft.fillScreen((0xFFFF));
svg.addCallback("time", printTime);
svg.addCallback("nr", printCounter);
svg.addCallback("dec", decrement);
svg.addCallback("inc", increment);
svg.readFile((char *)"/index.svg");
svg.print();
// list links
svg.linkManagement();
}
void loop2() {
uint16_t x, y;
static uint16_t color;
char * link;
static bool clicked = false;
if (tft.getTouch(&x, &y)) {
if (svg.onClick(x, y, &link)) {
Serial.printf("pressed: #%s#\n", link);
free(link);
}
}
}