/**
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 <WiFi.h>
#include <Wire.h>
#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 <RTClib.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);
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET 0
#define UTC_OFFSET_DST 1
#define imageWidth 209
#define imageHeight 148
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");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void MenuSet(){
tft.fillRoundRect(20, 100, 200, 50, 30, ILI9341_CYAN);
tft.setCursor(100, 118);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.print("Hour");
//delay(1000);
tft.fillRoundRect(20, 155, 200, 50, 30, ILI9341_BLUE);
tft.setCursor(100, 175);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.print("Date");
//delay(1000);
tft.fillRoundRect(20, 210, 200, 50, 30, ILI9341_YELLOW);
tft.setCursor(60, 230);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.print("Temperature");
delay(1000);
/* TS_Point p = ctp.getPoint();
int xcor = 240 - p.x;
int ycor = 320 - p.y;
if (ctp.touched()) {
if(xcor>20 && ycor>100 && xcor<20+200 && ycor<100+50){
Serial.println("ON pressed");
tft.fillScreen(ILI9341_BLACK);
}
*/
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
// LCD.setCursor(0, 1);
Serial.println("Connection Err");
return;
}
tft.setCursor(35, 70);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(3);
tft.println(&timeinfo, "%H:%M:%S");
tft.setCursor(12, 40);
tft.setTextColor(ILI9341_GREEN, ILI9341_BLACK);
tft.setTextSize(2 );
tft.println(&timeinfo, "%d/%m/%Y,%A");
}
/*
bool SetTimeFromNTPServer() {
bool ReturnValue = false;
configTime(0, 0, ntpServer); // get the UTC time from an internet ntp server (try 2)
if (getLocalTime(&timeinfo)) {
if (DEBUG_ENABLED) {
Serial.println("Setting time from NTP server");
Serial.print("NTP UTC server time: ");
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}
int y = timeinfo.tm_year + 1900;
int mo = timeinfo.tm_mon + 1;
int d = timeinfo.tm_mday;
int h = timeinfo.tm_hour;
int m = timeinfo.tm_min;
int s = timeinfo.tm_sec;
setTime(h, m, s, d, mo, y);
ReturnValue = (rtc.set(now()) == 0);
};
if (DEBUG_ENABLED)
if (ReturnValue)
Serial.println(“RTC set from NTP server”);
else
Serial.println(“Failed to set RTC from NTP server”);
return ReturnValue;
}*/
void loop() {
/* TS_Point p = ctp.getPoint();
int xcor = 240 - p.x;
int ycor = 320 - p.y;
MenuSet();
if (ctp.touched()) {
if(xcor>20 && ycor>100 && xcor<20+200 && ycor<100+50){
Serial.println("ON pressed");
tft.fillScreen(ILI9341_BLACK); delay(5000);
}
}*/
// tft.drawBitmap(100, 20 ,bitmap ,50 ,50 ,ILI9341_RED);
//printLocalTime();
tft.drawCircle(214, 42, 20, ILI9341_WHITE);
tft.drawCircle(214, 42, 21, ILI9341_WHITE);
tft.drawCircle(214, 42, 22, ILI9341_WHITE);
delay(1000);
}
////////////////////////////////////////////////////////////////////////////////////
// /*
// 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);
// }