#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);
int hour = 12; // Initial hour valu
int minute = 30; // Initial minute value
int savedHour = 12; // To save the adjusted hour
int savedMinute = 30; // To save the adjusted minute
// Size of the color selection boxes and the paintbrush size
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);
// drawTimeScreen();
drawSettingsIcon(100, 120, 30, ILI9341_BLUE);
}
void hourAdjust(){
TS_Point p = ctp.getPoint();
int x = 240 - p.x;
int y = 320 - p.y;
if (x > 50 && x < 100 && y > 100 && y < 150) { // Hour "+"
hour = hour + 1;
if (hour > 23) {
hour = 0; // Wrap around to 0 after 23
// drawTimeScreen();
}
}
if (x > 150 && x < 200 && y > 100 && y < 150) { // Hour "-"
hour = hour - 1;
if (hour < 0){
hour = 23; // Wrap around to 23 after 0
// drawTimeScreen();
}
}
/*tft.setCursor(25, 20);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(hour);*/
// drawTimeScreen();
tft.setCursor(20, 20);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print("Time: ");
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
if (hour < 10){
tft.print("0"); // Add leading zero to minutes
}
tft.print(hour, DEC);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(":");
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
if (minute < 10){
tft.print("0"); // Add leading zero to minutes
} tft.print(minute, DEC);
}
void minuteAdjust (){
TS_Point p = ctp.getPoint();
int xm = 240 - p.x;
int ym = 320 - p.y;
if (xm > 50 && xm < 100 && ym > 200 && ym < 250) { // Minute "+"
minute = minute + 1;
if (minute > 59) {
minute = 0; // Wrap around to 0 after 59
// drawTimeScreen();
}
}
if (xm > 150 && xm < 200 && ym > 200 && ym < 250) { // Minute "-"
minute = minute - 1;
if (minute < 0){
minute = 59; // Wrap around to 59 after 0
// drawTimeScreen();
}
}
tft.setCursor(20, 20);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print("Time: ");
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
if (hour < 10){
tft.print("0"); // Add leading zero to minutes
}
tft.print(hour, DEC);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(":");
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
if (minute < 10){
tft.print("0"); // Add leading zero to minutes
} tft.print(minute, DEC);
}
void drawTimeScreen() {
// Clear the screen area
/* TS_Point p = ctp.getPoint();
int x = 240 - p.x;
int y = 320 - p.y;*/
tft.fillRect(0, 0, 240, 320, ILI9341_BLACK);
// Draw hour adjustment buttons
tft.fillRect(50, 100, 50, 50, ILI9341_BLUE); // Hour "+"
tft.setCursor(65, 115);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("+");
tft.fillRect(150, 100, 50, 50, ILI9341_BLUE); // Hour "-"
tft.setCursor(165, 115);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("-");
// Draw minute adjustment buttons
tft.fillRect(50, 200, 50, 50, ILI9341_BLUE); // Minute "+"
tft.setCursor(65, 215);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("+");
tft.fillRect(150, 200, 50, 50, ILI9341_BLUE); // Minute "-"
tft.setCursor(165, 215);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("-");
// Draw OK button
tft.fillRect(100, 270, 60, 50, ILI9341_GREEN); // OK
tft.setCursor(115, 285);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("OK");
// Display current hour and minute
/* tft.setCursor(20, 20);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print("Time: ");
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(hour);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(":");
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
if (minute < 10) tft.print("0"); // Add leading zero to minutes
tft.print(minute);*/
/*
if (x > 50 && x < 100 && y > 100 && y < 150) { // Hour "+"
hour++;
if (hour > 23) hour = 0; // Wrap around to 0 after 23
// drawTimeScreen();
}
else if (x > 150 && x < 200 && y > 100 && y < 150) { // Hour "-"
hour--;
if (hour < 0) hour = 23; // Wrap around to 23 after 0
// drawTimeScreen();
}
else if (x > 50 && x < 100 && y > 200 && y < 250) { // Minute "+"
minute++;
if (minute > 59) minute = 0; // Wrap around to 0 after 59
//drawTimeScreen();
}
else if (x > 150 && x < 200 && y > 200 && y < 250) { // Minute "-"
minute--;
if (minute < 0) minute = 59; // Wrap around to 59 after 0
//drawTimeScreen();
}
else if (x > 100 && x < 180 && y > 300 && y < 350) { // OK button
saveTime();
}*/
}
void saveTime() {
// Save the hour and minute adjustments
savedHour = hour;
savedMinute = minute;
// Display a confirmation message
// tft.fillScreen(ILI9341_BLACK);
tft.setCursor(70, 100);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Time Saved!");
tft.setCursor(60, 150);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(savedHour);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(":");
if (savedMinute < 10) tft.print("0"); // Add leading zero
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(savedMinute);
//delay(2000); // Display saved message for 2 seconds
//drawTimeScreen(); // Go back to the adjustment screen
}
void drawSettingsIcon(int x, int y, int radius, uint16_t color) {
// Main gear circle
tft.fillCircle(x, y, radius, color);
// Draw rectangular gear teeth around the main circle
int numTeeth = 8; // Number of gear teeth
int toothLength = 10; // Length of each tooth
int toothWidth = 6; // Width of each tooth
for (int i = 0; i < numTeeth; i++) {
float angle = i * (360.0 / numTeeth);
float angleRad = radians(angle);
// Calculate position for each tooth rectangle
int xOffset = cos(angleRad) * (radius + toothLength / 2);
int yOffset = sin(angleRad) * (radius + toothLength / 2);
// Calculate the rotated position of each rectangle's corners
int rectX = x + xOffset;
int rectY = y + yOffset;
// Rotate each tooth by its angle around the gear center
int rectWidth = toothWidth;
int rectHeight = toothLength;
int x1 = rectX - (rectWidth / 2);
int y1 = rectY - (rectHeight / 2);
int x2 = x1 + cos(angleRad) * rectHeight;
int y2 = y1 + sin(angleRad) * rectHeight;
// Draw each rectangle at calculated position
tft.fillRect(x1, y1, rectWidth, rectHeight, color);
}
// Hollow out the center of the gear
tft.fillCircle(x, y, radius / 2, ILI9341_BLACK);
/*
// Draw the wrench
int wrenchLength = 40;
int wrenchWidth = 8;
// Wrench handle (rectangle)
tft.fillRect(x + 15, y + 10, wrenchLength, wrenchWidth, color);
// Wrench head (semi-circle)
tft.fillCircle(x + 15 + wrenchLength, y + 10 + (wrenchWidth / 2), wrenchWidth, color);
tft.fillRect(x + 15 + wrenchLength, y + 10, wrenchWidth, wrenchWidth, ILI9341_BLACK);*/
}
void loop() {
// delay(10);
// Wait for a touch
if (! ctp.touched()) {
return;
}
//hourAdjust();
//minuteAdjust();
//drawMenu();
// Retrieve a point
/* int x = 240 - p.x;
int y = 320 - p.y;*/
//drawTimeScreen();
/*
// 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(")");*/
/*
TS_Point p = ctp.getPoint();
int x = 240 - p.x;
int y = 320 - p.y;
if (x > 50 && x < 100 && y > 100 && y < 150) { // Hour "+"
hour++;
if (hour > 23) {
hour = 0; // Wrap around to 0 after 23
// drawTimeScreen();
}
}
else if (x > 150 && x < 200 && y > 100 && y < 150) { // Hour "-"
hour--;
if (hour < 0){ hour = 23; // Wrap around to 23 after 0
// drawTimeScreen();
}
}
else if (x > 50 && x < 100 && y > 200 && y < 250) { // Minute "+"
minute++;
if (minute > 59) {
minute = 0; // Wrap around to 0 after 59
// drawTimeScreen();
}
}
else if (x > 150 && x < 200 && y > 200 && y < 250) { // Minute "-"
minute--;
if (minute < 0){ minute = 59; // Wrap around to 59 after 0
// drawTimeScreen();
}
}
else if (x > 100 && x < 180 && y > 300 && y < 350) { // OK button
saveTime();
}*/
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1
Loading
ili9341-cap-touch
ili9341-cap-touch