/**
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>
#include<Fonts/FreeSansOblique12pt7b.h>
#include "SdFat.h"
#define SPI_SPEED SD_SCK_MHZ(4)
#define CS_PIN 10
SdFat sd;
// 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 1
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();
tft.fillScreen(ILI9341_WHITE);
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.println(" ");
tft.println(" ");
tft.println(" ");
tft.println(" ");
tft.println(" ");
tft.println(" ");
tft.println(" ");
tft.println(" ");
tft.println(" SLATEBOOK GENESIS");
Serial.println("Capacitive touchscreen started");
delay(3000);
tft.fillScreen(ILI9341_WHITE);
Serial.begin(115200);
if (!sd.begin(CS_PIN, SPI_SPEED)) {
if (sd.card()->errorCode(e)) {
Serial.println(e);
} else if (sd.vol()->fatType() == 0) {
Serial.println("Can't find a valid FAT16/FAT32 partition.");
} else {
Serial.println("Can't determine error type");
}
return;
}
Serial.println("Files on card:");
Serial.println(" Size Name");
sd.ls(LS_R | LS_SIZE);
}
void loop() {
// Wait for a touch
if (! ctp.touched()) {
return;
}
tft.drawLine(50, 320, 50, 0,ILI9341_BLACK);
for(int num_line=1;num_line<25;num_line++){
tft.drawLine(0, 320-num_line*16, 240, 320-num_line*16,ILI9341_BLACK);
}
// tft.drawLine(0, 140, 240, 140,ILI9341_BLACK);
TS_Point p = ctp.getPoint();
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
tft.drawRect(10, 10, 30, 320,ILI9341_RED);
//}
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
}
}
//void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
////////////////////////////////////////////////////////////////////////////////////
// /*
// ESP32-S3 + ILI9341 TFT LCD Example
// https://wokwi.com/projects/343784047735997012
// */
// #include "SPI.h"
// #include "Adafruit_GFX.h"
// #include "Adafruit_ILI9341.h"
// #define TFT_DC 2
// #define TFT_CS 15
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// void setup() {
// Serial.begin(115200);
// Serial.println("Welcome to Wokwi, ESP32-S3");
// Wire.begin(10,8);
// tft.begin();
// tft.setCursor(44, 120);
// tft.setTextColor(ILI9341_RED);
// tft.setTextSize(3);
// tft.println("ESP32-S3");
// }
// const uint32_t colors[] = {
// ILI9341_GREEN,
// ILI9341_CYAN,
// ILI9341_MAGENTA,
// ILI9341_YELLOW,
// };
// uint8_t colorIndex = 0;
// void loop() {
// tft.setTextSize(2);
// tft.setCursor(26, 164);
// tft.setTextColor(colors[colorIndex++ % 4]);
// tft.println("Welcome to Wokwi!");
// delay(250);
// }