/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
ESP32 display
3v3 VCC
GND GND
5 TFT_CS
25 TFT_RESET
2 TFT_DC
23 MOSI
18 SCK
3v3 LED
19 MISO
ESP32 Encoder
32 select button 1
GND select button 2
27 encoder direction 1
33 encoder direction 2
GND encoder dir ground
// For the Adafruit shield, these are the default.
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
*/
#include "Adafruit_GFX.h"
#include <SPI.h>
#include "Adafruit_ILI9341.h"
#include <Arduino.h> // this is needed for FT6206
#include "Adafruit_FT6206.h"
// ----------- Dokunmatik touchpad tanımlama
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 5
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define cy tft.height()/2
#define cx tft.width()/2
void setup() {
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
Wire.setPins(21,22); // SDA:10 SCL:8 redefine first I2C port to be on pins 10/8
Wire.begin();
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");
//Ekrana beyaz tabanda hello yazdırma
tft.fillScreen(0xFFFF);
tft.setCursor(45,cy);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(4);
tft.println("HELLO");
delay(3000);
tft.fillScreen(0x0000);
}
void loop(){
HOME(); if (! ctp.touched()) { return; }
MENU(); if (! ctp.touched()) { return; }
BUTTONS(); if (! ctp.touched()) { return; }
DISP(); if (! ctp.touched()) { return; }
// delay(10); //10 bekle
// Wait for a touch
if (! ctp.touched()) { // Ekrana basıldığında alt satırları işle
return;
}
// Retrieve a point Dokunmatikten değer okuma ve seri port ile yazdırma
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(" -> ");
// 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);
// Print out the remapped (rotated) coordinates
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
}
void HOME(){
int16_t cxb = tft.width()/2 + 10; //offset x
int16_t cyb = tft.height()/2; // offset y
tft.setCursor(cxb - 48,10);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("HOME"); //18 x 96?
tft.fillRect(10,(cyb+8),128,25,ILI9341_YELLOW);
tft.setCursor(24,(cyb+10));
tft.setTextColor(ILI9341_BLACK);
//@param s Desired text size. 1 is default 6x8, 2 is 12x16, 3 is 18x24, etc
tft.setTextSize(2);
tft.println("1.Display");
tft.fillRect(10,(cyb+38),128,25,ILI9341_YELLOW);
tft.setCursor(20,(cyb+40));
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(3);
tft.println("2.Menu");
tft.fillRect(10,(cyb+68),128,25,ILI9341_YELLOW);
tft.setCursor(20,(cyb+70));
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(3);
tft.println("3.Info");
//SELECTION BOXES
tft.drawRect(10,(cyb+8),128,25,ILI9341_WHITE);
tft.drawRect(10,(cyb+38),128,25,ILI9341_WHITE);
tft.drawRect(10,(cyb+68),128,25,ILI9341_WHITE);
}
void DISP(){
tft.setCursor(10,10);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Live Display");
tft.setCursor(10,(cy-100));
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(6);
tft.println("273.5k");
tft.fillRect(10,(cy+8),128,25,ILI9341_YELLOW);
tft.setCursor(20,(cy+10));
tft.setTextColor(ILI9341_BLACK);
//@param s Desired text size. 1 is default 6x8, 2 is 12x16, 3 is 18x24, etc
tft.setTextSize(3);
tft.println("1.TEMP");
tft.fillRect(10,(cy+38),128,25,ILI9341_YELLOW);
tft.setCursor(20,(cy+40));
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(3);
tft.println("2.VOLT");
}
void MENU(){
int16_t cxb = tft.width()/2 + 10; //offset x
int16_t cyb = tft.height()/2; // offset y
tft.fillRect(10,(cyb+8),128,25,ILI9341_YELLOW);
tft.setCursor(20,(cyb+10));
tft.setTextColor(ILI9341_BLACK);
//@param s Desired text size. 1 is default 6x8, 2 is 12x16, 3 is 18x24, etc
tft.setTextSize(2);
tft.println("1.CH1");
tft.fillRect(10,(cyb+38),128,25,ILI9341_YELLOW);
tft.setCursor(20,(cyb+40));
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(3);
tft.println("2.CH2");
}
void BUTTONS(){
int16_t cxb = tft.width()/2 + 10; //offset x
int16_t cyb = tft.height()/2; // offset y
tft.fillRoundRect((cxb+50),(cyb+40),30,30,5,ILI9341_GREEN);
//height = 23
tft.fillTriangle((cxb+50),(cyb+38),(cxb+80),(cyb+38),(cxb+65),(cyb+15),ILI9341_GREEN);//top
tft.fillTriangle((cxb+50),(cyb+72),(cxb+80),(cyb+72),(cxb+65),(cyb+95),ILI9341_GREEN);//bot
tft.fillTriangle((cxb+48),(cyb+40),(cxb+25),(cyb+55),(cxb+48),(cyb+70),ILI9341_GREEN);//left
tft.fillTriangle((cxb+82),(cyb+40),(cxb+105),(cyb+55),(cxb+82),(cyb+70),ILI9341_GREEN);//right
}