#define BLYNK_TEMPLATE_ID "TMPL4B3wGVOxo"
#define BLYNK_TEMPLATE_NAME "esp32 smart switch"
#define BLYNK_AUTH_TOKEN "8vos0XBl2CrvRRujfFogw7Nc4VzNUdr6"
#define GUI_MODE_LAMP 1
#define GUI_MODE_MUSIC 2
#define GUI_MODE_SETTINGS 3
#define GUI_MODE_OTHER 4
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
//#include <ILI9341_t3n.h>
#include <Adafruit_ILI9341.h>
#include <Arduino.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
//------ SD stuff below ------
#include <SdFat.h>
//SdFat SD; // SD card filesystem
//Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
//File root;
// ----- Blynk stuff below --------
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// ------ Screen stuff below --------
// 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
#define TFT_RST 4
#define SD_CS_PIN 5
#define ILI9341_TFTWIDTH 320
#define ILI9341_TFTHEIGHT 240
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
//--- Not working --- ---Implement later with real hardware ---
// Let's allocate the frame buffer ourself.
//DMAMEM uint16_t tft_frame_buffer[ILI9341_TFTWIDTH * ILI9341_TFTHEIGHT];
// Size of the color selection boxes and the paintbrush size
#define RECTWIDTH 160
#define RECTHEIGHT 20
#define SLIDER_X 200
#define SLIDER_Y 30
#define SLIDERWIDTH 80
#define SLIDERHEIGHT 180
#define SLIDER_ELEMENTS 12
int mode = 1;
// Global variables for checking between google and local
bool lampOn;
bool musicOn;
uint16_t lampDimmerLevel, volumeLevel;
void drawFrame()
{
tft.fillScreen(ILI9341_BLACK);
}
/*void drawLampButtonON()
{
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
drawFrame();
tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("ON");
RecordOn = true;
}
void drawLampButtonOFF()
{
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
drawFrame();
tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("OFF");
RecordOn = false;
}*/
void turnLampON()
{
//Switch via Google
//Check if google is switched via other sources
}
void turnLampOFF()
{
//Switch via Google
//Check if google is switched via other sources
}
void drawLightSlider()
{
//Drawing the slider for dimming light
}
void drawVolumeSlider()
{
//Drawing the slider for dimming light
//tft.fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
//The outline
tft.drawRoundRect(200, 30, SLIDERWIDTH, SLIDERHEIGHT, 8, ILI9341_CYAN);
//The slider elements
for (int i = 0; i < (volumeLevel / 100)*SLIDER_ELEMENTS; i++)
{
tft.drawRoundRect(SLIDER_X+3, SLIDER_Y+4 + (SLIDERHEIGHT/SLIDER_ELEMENTS)*i-1, SLIDERWIDTH-6, (SLIDERHEIGHT/SLIDER_ELEMENTS)-4, 5, ILI9341_CYAN);
}
}
bool checkLamp()
{
}
uint16_t checkLampDimmerLevel()
{
}
uint16_t checkVolumeLevel()
{
}
void checkTouchMusicMenu()
{
}
void checkTouchSettingsMenu()
{
}
void setup() {
Serial.begin(115200);
/*
// ----- SD card stuff ------
//Start SD card
if (!SD.begin(CS_PIN)) {
Serial.println("Card initialization failed!");
while (true);
}
//Load graphics from SD card
Adafruit_Image lamp_on;
Adafruit_Image lamp_off;
Adafruit_Image arrow;
Adafruit_Image play_button;
stat = reader.loadBMP("/wales.bmp", img);
ImageReturnCode stat;
stat = reader.loadBMP("/wales.bmp", lamp_on);
stat = reader.loadBMP("/wales.bmp", lamp_off);
stat = reader.loadBMP("/wales.bmp", arrow);
stat = reader.loadBMP("/wales.bmp", play_button);
*/
//Start Blynk
Blynk.begin(auth, ssid, pass);
//Start screen
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.setRotation(1);
//Standard screen
tft.fillScreen(ILI9341_BLACK);
volumeLevel = 100;
//Turn on frame buffer ---- NOT WORKING ----- OTHER LIBRARY
//tft.setFrameBuffer(tft_frame_buffer);
//tft.useFrameBuffer(true);
}
void loop() {
// Wait for a touch - Remove later
delay(10);
if (! ctp.touched()) {
return;
}
// put your main code here, to run repeatedly:
//delay(10); // this speeds up the simulation
switch (mode) {
case GUI_MODE_LAMP:
//Lamp menu - Default mode
//tft.fillScreen(ILI9341_BLACK);
// make the color selection boxes
drawFrame();
drawVolumeSlider();
break;
case GUI_MODE_MUSIC:
//Music menu
drawFrame();
drawVolumeSlider();
break;
case GUI_MODE_SETTINGS:
//Settings menu
break;
case GUI_MODE_OTHER:
//Other menu or what ever
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
//delay(10);
// Retrieve a point
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.
int x_temp = p.x;
int y_temp = p.y;
p.x = map(y_temp, 0, ILI9341_TFTWIDTH, 0, ILI9341_TFTWIDTH);
p.y = map(x_temp, 0, ILI9341_TFTHEIGHT, ILI9341_TFTHEIGHT, 0);
// Print out the remapped (rotated) coordinates
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
//Checking touch
}
Loading
ili9341-cap-touch
ili9341-cap-touch