#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Arduino.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
//#include <U8g2_for_Adafruit_GFX.h>
Adafruit_FT6206 ctp = Adafruit_FT6206();
//------------------------------
// Set the legs of the TFT screen.
#define TFT_DC 15
#define TFT_CS 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
uint8_t Current_Menu;
uint8_t Sensor1_Menu;
Adafruit_GFX_Button Q_Button,W_Button,E_Button,R_Button,T_Button,Y_Button,U_Button,I_Button,O_Button,P_Button,
A_Button,S_Button,D_Button,F_Button,G_Button,H_Button,J_Button,K_Button,L_Button;
Adafruit_GFX_Button Back_Button, Sensor1_Button,Sensor2_Button,Sensor4_Button,Sensor3_Button;
Adafruit_GFX_Button RBack_Button, RSensor1_Button,RSensor2_Button,RSensor4_Button,RSensor3_Button;
#define BLACK 0x0000
#define WHITE 0xFFFF
int back;
int button_size = 32;
int buttons_margin_row_1 = button_size/2;
String pass = "2";
void setup(void) {
//while (!Serial); // used for leonardo debugging
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
//Wire.begin(); // redefine first I2C port to be on pins 10/8
tft.begin();
tft.setRotation(1);
tft.fillScreen(0x22d1);
Q_Button.initButton(&tft, buttons_margin_row_1, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "q",2);
W_Button.initButton(&tft, buttons_margin_row_1+button_size, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "w",2);
E_Button.initButton(&tft, buttons_margin_row_1+button_size*2, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "e",2);
R_Button.initButton(&tft, buttons_margin_row_1+button_size*3, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "r",2);
T_Button.initButton(&tft, buttons_margin_row_1+button_size*4, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "t",2);
Y_Button.initButton(&tft, buttons_margin_row_1+button_size*5, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "y",2);
U_Button.initButton(&tft, buttons_margin_row_1+button_size*6, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "u",2);
I_Button.initButton(&tft, buttons_margin_row_1+button_size*7, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "i",2);
O_Button.initButton(&tft, buttons_margin_row_1+button_size*8, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "o",2);
P_Button.initButton(&tft, buttons_margin_row_1+button_size*9, 140, button_size, button_size, 0x0000, WHITE, 0x463f, "p",2);
A_Button.initButton(&tft, 16+buttons_margin_row_1, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "a",2);
S_Button.initButton(&tft, 16+buttons_margin_row_1+button_size, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "s",2);
D_Button.initButton(&tft, 16+buttons_margin_row_1+button_size*2, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "d",2);
F_Button.initButton(&tft, 16+buttons_margin_row_1+button_size*3, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "f",2);
G_Button.initButton(&tft, 16+buttons_margin_row_1+button_size*4, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "g",2);
H_Button.initButton(&tft, 16+buttons_margin_row_1+button_size*5, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "h",2);
J_Button.initButton(&tft, 16+buttons_margin_row_1+button_size*6, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "j",2);
K_Button.initButton(&tft, 16+buttons_margin_row_1+button_size*7, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "k",2);
L_Button.initButton(&tft, 16+buttons_margin_row_1+button_size*8, 172, button_size, button_size, 0x0000, WHITE, 0x463f, "l",2);
Sensor1_Button.initButton(&tft, 55, 140, 130, 40, 0x0000, WHITE, 0x463f, " Sensor 1",2);
Sensor2_Button.initButton(&tft, 55, 195, 130, 40, 0x463f, WHITE, 0x463f, " Sensor 2",2);
Sensor3_Button.initButton(&tft, 260, 140, 130, 40, 0x463f, WHITE, 0x463f, "Sensor 3",2);
Sensor4_Button.initButton(&tft, 260, 195, 130, 40, 0x463f, WHITE, 0x463f, "Sensor 4",2);
RSensor1_Button.initButton(&tft, 55, 140, 130, 40, WHITE, 0x463f, WHITE, " Sensor 1",2);
RSensor2_Button.initButton(&tft, 55, 195, 130, 40, WHITE, 0x463f, WHITE, " Sensor 2",2);
RSensor3_Button.initButton(&tft, 260, 140, 130, 40, WHITE, 0x463f, WHITE, "Sensor 3",2);
RSensor4_Button.initButton(&tft, 260, 195, 130, 40, WHITE, 0x463f, WHITE, "Sensor 4",2);
Back_Button.initButton(&tft, 280, 200, 90, 40, 0x463f, WHITE, 0x463f, "Back",2);
RBack_Button.initButton(&tft, 280, 200, 90, 40, WHITE, 0x463f, WHITE, "Back",2);
Change_Menu(1);
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
}
void Change_Menu(uint8_t no){
Current_Menu = no;
switch(no){
case 1:
Draw_Main_Menu();
break;
case 2:
Draw_Sensor1_Menu();
break;
case 3:
Draw_Sensor2_Menu();
break;
case 4:
Draw_Sensor3_Menu();
break;
case 5:
Draw_Sensor4_Menu();
break;
}
}
void Draw_Main_Menu()
{
tft.fillScreen(0x22d1);
tft.setCursor(80,50);
tft.setTextColor(0xFFFF);
tft.setTextSize(4.2);
tft.print(("WELCOME!"));
Sensor1_Button.drawButton(true);
Sensor2_Button.drawButton(true);
Sensor3_Button.drawButton(true);
Sensor4_Button.drawButton(true);
back=1;
}
void Draw_Sensor1_Menu()
{
tft.fillScreen(0x22d1);
tft.fillRect(3,3,150,20,0xFFFF);
tft.setCursor(5,6);
tft.setTextSize(2);
tft.setTextColor(0x22d1);
tft.print(pass);
Q_Button.drawButton(true);
W_Button.drawButton(true);
E_Button.drawButton(true);
R_Button.drawButton(true);
T_Button.drawButton(true);
Y_Button.drawButton(true);
U_Button.drawButton(true);
I_Button.drawButton(true);
O_Button.drawButton(true);
P_Button.drawButton(true);
A_Button.drawButton(true);
S_Button.drawButton(true);
D_Button.drawButton(true);
F_Button.drawButton(true);
G_Button.drawButton(true);
H_Button.drawButton(true);
J_Button.drawButton(true);
K_Button.drawButton(true);
L_Button.drawButton(true);
back=0;
}
void Draw_Sensor2_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
Back_Button.drawButton(true);
back=0;
}
void Draw_Sensor3_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
Back_Button.drawButton(true);back=0;
}
void Draw_Sensor4_Menu()
{
tft.setRotation(1);
tft.fillScreen(0x22d1);
Back_Button.drawButton(true);back=0;
}
void loop()
{
delay(10);
if (! ctp.touched()) {
return;
}
TS_Point p = ctp.getPoint();
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
if(p.x>=120 && p.x<=160)
{
if (p.y>=200 && p.y <=320)
{RSensor1_Button.drawButton(true);
delay(200);
Sensor1_Button.drawButton(true);
delay(50);
Change_Menu(2);
}
else if (p.y>=0 && p.y<=125)
{
RSensor3_Button.drawButton(true);
delay(200);
Sensor3_Button.drawButton(true);
delay(50);
Change_Menu(4);
}
}
if (Q_Button.contains(p.x, p.y)) {
Serial.print("Pressing: Q");
//buttons[b].press(true); // tell the button it is pressed
} else {
//buttons[b].press(false); // tell the button it is NOT pressed
}
// if ( back ==1)
// {
// if(p.x>=120 && p.x<=160)
// {
// if (p.y>=200 && p.y <=320)
// {RSensor1_Button.drawButton(true);
// delay(200);
// Sensor1_Button.drawButton(true);
// delay(50);
// Change_Menu(2);
// }
// else if (p.y>=0 && p.y<=125)
// {
// RSensor3_Button.drawButton(true);
// delay(200);
// Sensor3_Button.drawButton(true);
// delay(50);
// Change_Menu(4);
// }
// }
// else if (p.x >=175 && p.x <=215 )
// {
// if (p.y >=200 && p.y <=320)
// {
// RSensor2_Button.drawButton(true);
// delay(200);
// Sensor2_Button.drawButton(true);
// delay(50);
// Change_Menu(3);
// }
// else if (p.y >=0 && p.y<=125)
// {
// RSensor4_Button.drawButton(true);
// delay(200);
// Sensor4_Button.drawButton(true);
// delay(50);
// Change_Menu(5);
// }
// }
// }
// else
// {
// if (p.x>=180 && p.x <=220 )
// {
// if(p.y >=0 && p.y <=85 ){
// RBack_Button.drawButton(true);
// delay(200);
// Back_Button.drawButton(true);
// delay(50);
// Change_Menu(1);
// }
// }
// }
}