/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
//#include "bitmaps.h"
//#include <avr/pgmspace.h>
#include "Wire.h"
#include "Adafruit_FT6206.h"
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000
// The STMPE610 uses hardware SPI on the shield, and #8
#define STMPE_CS 8
//Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int oldcolor, currentcolor;
#define cy tft.height()/2
#define cx tft.width()/2
Adafruit_FT6206 ctp = Adafruit_FT6206();
void setup() {
Serial.begin(115200);
Wire.setPins(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");
}
void loop(){
// int16_t w = 60, height 100;
// center(&w, &height);
//drawBitmap(60, 100, Triangle, 60, 60, ILI9341_RED);
//HELLO();
HOME();
//DISP();
BUTTONS();
delay(50000);
}
void drawBitmap(int16_t x, int16_t y,
const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color) {
int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
uint8_t byte = 0;
for(int16_t j=0; j<h; j++, y++) {
for(int16_t i=0; i<w; i++) {
if(i & 7) byte <<= 1;
else byte = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
if(byte & 0x80) tft.drawPixel(x+i, y, color);
}
}
}
void HELLO(){
tft.fillScreen(0xFFFF);
tft.setCursor(45,cy);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(4);
tft.println("HELLO");
delay(3000);
tft.fillScreen(0x0000);
}
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
}