/**
Arduino MEGA adaptation by https://wokwi.com/makers/gjchen
First demo for FT6206 Capactive Touch Screen on Wokwi. Enjoy!
https://wokwi.com/arduino/projects/376916542459428865
*/
/**
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 53
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// Size of the color selection boxes and the paintbrush size
void Change_Menu(uint8_t);
uint8_t Current_Menu;
uint8_t Sensor1_Menu;
Adafruit_GFX_Button Back_Button, Sensor1_Button,Sensor2_Button,Sensor4_Button,Sensor3_Button;
Adafruit_GFX_Button RBack_Button, RSensor1_Button,RSensor2_Button,RSensor4_Button,RSensor3_Button;
#define BLACK 0x0000
#define WHITE 0xFFFF
int back;
void setup(void) {
//while (!Serial); // used for leonardo debugging
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
Wire.begin(); // redefine first I2C port to be on pins 10/8
tft.begin();
tft.setRotation(1);
tft.fillScreen(0x22d1);
Sensor1_Button.initButton(&tft, 55, 140, 130, 40, 0x463f, WHITE, 0x463f, " Sensor 1",2);
Sensor2_Button.initButton(&tft, 55, 195, 130, 40, 0x463f, WHITE, 0x463f, " Sensor 2",2 );
Sensor3_Button.initButton(&tft, 260, 140, 130, 40, 0x463f, WHITE, 0x463f, "Sensor 3",2 );
Sensor4_Button.initButton(&tft, 260, 195, 130, 40, 0x463f, WHITE, 0x463f, "Sensor 4",2 );
RSensor1_Button.initButton(&tft, 55, 140, 130, 40, WHITE, 0x463f, WHITE, " Sensor 1",2);
RSensor2_Button.initButton(&tft, 55, 195, 130, 40, WHITE, 0x463f, WHITE, " Sensor 2",2);
RSensor3_Button.initButton(&tft, 260, 140, 130, 40, WHITE, 0x463f, WHITE, "Sensor 3",2);
RSensor4_Button.initButton(&tft, 260, 195, 130, 40, WHITE, 0x463f, WHITE, "Sensor 4",2);
Back_Button.initButton(&tft, 280, 200, 90, 40, 0x463f, WHITE, 0x463f, "Back",2);
RBack_Button.initButton(&tft, 280, 200, 90, 40, WHITE, 0x463f, WHITE, "Back",2);
Change_Menu(1);
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
}
void Change_Menu(uint8_t no){
Current_Menu = no;
switch(no){
case 1:
Draw_Main_Menu();
break;
case 2:
Draw_Sensor1_Menu();
break;
case 3:
Draw_Sensor2_Menu();
break;
case 4:
Draw_Sensor3_Menu();
break;
case 5:
Draw_Sensor4_Menu();
break;
}
}
void Draw_Main_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
tft.setCursor(80,50);
tft.setTextColor(0xFFFF);
tft.setTextSize(4.2);
tft.print(("WELCOME!"));
Sensor1_Button.drawButton(true);
Sensor2_Button.drawButton(true);
Sensor3_Button.drawButton(true);
Sensor4_Button.drawButton(true);
back=1;
}
void Draw_Sensor1_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
Back_Button.drawButton(true);
back=0;
}
void Draw_Sensor2_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
Back_Button.drawButton(true);
back=0;
}
void Draw_Sensor3_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
Back_Button.drawButton(true);back=0;
}
void Draw_Sensor4_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
Back_Button.drawButton(true);back=0;
}
void loop()
{
delay(10);
if (! ctp.touched()) {
return;
}
TS_Point p = ctp.getPoint();
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
if ( back ==1){
if (p.x>=120 && p.x<=160)
{
if (p.y>=200 && p.y <=320)
{RSensor1_Button.drawButton(true);
delay(200);
Sensor1_Button.drawButton(true);
delay(50);
Change_Menu(2);
}
else if (p.y>=0 && p.y<=125)
{
RSensor3_Button.drawButton(true);
delay(200);
Sensor3_Button.drawButton(true);
delay(50);
Change_Menu(4);
}
}
else if (p.x >=175 && p.x <=215 )
{
if (p.y >=200 && p.y <=320)
{
RSensor2_Button.drawButton(true);
delay(200);
Sensor2_Button.drawButton(true);
delay(50);
Change_Menu(3);
}
else if (p.y >=0 && p.y<=125)
{
RSensor4_Button.drawButton(true);
delay(200);
Sensor4_Button.drawButton(true);
delay(50);
Change_Menu(5);
}
}
}
else{
if (p.x>=180 && p.x <=220 )
{
if(p.y >=0 && p.y <=85 ){
RBack_Button.drawButton(true);
delay(200);
Back_Button.drawButton(true);
delay(50);
Change_Menu(1);}}}
}
////////////////////////////////////////////////////////////////////////////////////
// /*
// 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);
// }