Hello! So, I want to do a Arduino project where is essential to have a keyboard. I bought an Adafruit TFT Shield with touchscreen (0x8357) and made the keyboard which works. Now, the thing is I also need symbols and digits, not just letters. So, I created a keyboard with those, which in theory should be activated when I touch a certain button on the virtual keyboard. Now, there is one problem. The keys i press on the virtual keyboard are displayed in the Serial Monitor, and when it comes to letters, it works good. But, when I press the button to switch to digits and symbols, the keyboard on the screen remains the same, although on the Serial Monitor are displayed the digits and symbols which correspond to that key position( https://drive.google.com/file/d/1dCnn0w5W41iYbBhhX3DVwj9HFe6V8MpT/view?usp=sharing ). To change the keyboards, I initially put a black rectangle over the current one(because there is no option in the library to clean text, or at least I haven't found one), then I put the new keyboard over. I should also mention the fact that when I try to alternatively print them(https://drive.google.com/file/d/1dFVqn4bwhkmNplk80VtbfgmkLmzNQ5Q_/view?usp=sharing ), it works without any problem, so it's probably something about the touch. I will also attach the code, because maybe I didn't saw something. Also, the same thing happens when I try to print the character I touch directly on the display(i touch the character, and the screen becomes white). So, how can I solve this issue?
Code:
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <stdint.h>
#include "TouchScreen.h"
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GOLD 0xEA8B02
#define GRAY 0xCCCCFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(7, A2, A1, 6, 300);
int mode = 1;
void tast_litere()
{
tft.fillRect(5, 185, 185, 120, BLACK);
tft.drawRect(5, 185, 185, 120, YELLOW);
tft.setCursor(10, 190);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("QWERTYUIOP");
tft.setCursor(20, 220);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("ASDFGHJKL");
tft.setCursor(30, 250);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("ZXCVBNM");
tft.fillRect(195, 280, 40, 30, GRAY);
tft.setCursor(200, 285);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.print("OK");
tft.fillRect(195, 200, 40, 30, GRAY);
tft.setCursor(200, 205);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.print("<-");
tft.fillRect(195, 240, 40, 30, GRAY);
tft.setCursor(200, 245);
tft.setTextColor(MAGENTA);
tft.setTextSize(3);
tft.print("?1");
tft.setCursor(50, 280);
tft.setTextColor(BLUE);
tft.setTextSize(3);
tft.print("SPACE");
tft.drawRect(45, 275, 100, 30, YELLOW);
}
void tast_cif_simb()
{
tft.fillRect(5, 185, 185, 120, BLACK);
tft.drawRect(5, 185, 185, 120, YELLOW);
tft.setCursor(10, 190);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("1234567890");
tft.setCursor(10, 220);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("@#$_&-+()/");
tft.setCursor(30, 250);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("*':;!?=%");
tft.fillRect(195, 280, 40, 30, GRAY);
tft.setCursor(200, 285);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.print("OK");
tft.fillRect(195, 200, 40, 30, GRAY);
tft.setCursor(200, 205);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.print("<-");
tft.fillRect(195, 240, 40, 30, GRAY);
tft.setCursor(200, 245);
tft.setTextColor(MAGENTA);
tft.setTextSize(3);
tft.print("AB");
tft.setCursor(52, 280);
tft.setTextColor(BLUE);
tft.setTextSize(3);
tft.print("SPACE");
tft.drawRect(45, 275, 100, 30, YELLOW);
}
void setup() {
Serial.begin(9600);
tft.reset();
tft.begin(0x8357);
tft.fillScreen(BLACK);
tft.setRotation(2);
tast_litere();
}
void loop() {
// a point object holds x y and z coordinates
TSPoint p = ts.getPoint();
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > ts.pressureThreshhold) {
/**Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);
Serial.print(mode);
Serial.print(' '); **/
if(mode == 1)
{
if(p.x >= 750 && p.x <= 885 && p.y >= 650 && p.y <= 720)
Serial.print("del");
else if(p.x >= 775 && p.x <= 890 && p.y >= 830 && p.y <= 905)
Serial.print("OK");
else if(p.x >= 770 && p.x <= 895 && p.y >= 745 && p.y <= 805)
{
mode = 2;
tast_cif_simb();
}
else if(p.x >= 280 && p.x <= 595 && p.y >= 830 && p.y <= 895)
Serial.print(" ");
else if(p.y >= 610 && p.y <= 660)
{
if(p.x >= 160 && p.x <= 215)
Serial.print('Q');
else if(p.x >= 220 && p.x <= 275)
Serial.print('W');
else if(p.x >= 280 && p.x <= 335)
Serial.print('E');
else if(p.x >= 340 && p.x <= 395)
Serial.print('R');
else if(p.x >= 400 && p.x <= 455)
Serial.print('T');
else if(p.x >= 460 && p.x <= 515)
Serial.print('Y');
else if(p.x >= 520 && p.x <= 575)
Serial.print('U');
else if(p.x >= 580 && p.x <= 635)
Serial.print('I');
else if(p.x >= 640 && p.x <= 695)
Serial.print('O');
else if(p.x >= 700 && p.x <= 755)
Serial.print('P');
}
else if(p.y >= 680 && p.y <= 730)
{
if(p.x >= 185 && p.x <= 240)
Serial.print('A');
else if(p.x >= 245 && p.x <= 300)
Serial.print('S');
else if(p.x >= 305 && p.x <= 360)
Serial.print('D');
else if(p.x >= 365 && p.x <= 420)
Serial.print('F');
else if(p.x >= 425 && p.x <= 480)
Serial.print('G');
else if(p.x >= 485 && p.x <= 540)
Serial.print('H');
else if(p.x >= 545 && p.x <= 600)
Serial.print('J');
else if(p.x >= 605 && p.x <= 660)
Serial.print('K');
else if(p.x >= 665 && p.x <= 720)
Serial.print('L');
}
else if(p.y >= 750 && p.y <= 800)
{
if(p.x >= 235 && p.x <= 290)
Serial.print('Z');
else if(p.x >= 295 && p.x <= 350)
Serial.print('X');
else if(p.x >= 355 && p.x <= 410)
Serial.print('C');
else if(p.x >= 415 && p.x <= 470)
Serial.print('V');
else if(p.x >= 475 && p.x <= 530)
Serial.print('B');
else if(p.x >= 535 && p.x <= 590)
Serial.print('N');
else if(p.x >= 595 && p.x <= 650)
Serial.print('M');
}
}
else
{
if(p.x >= 750 && p.x <= 885 && p.y >= 650 && p.y <= 720)
Serial.print("del");
else if(p.x >= 775 && p.x <= 890 && p.y >= 830 && p.y <= 905)
Serial.print("OK");
else if(p.x >= 770 && p.x <= 895 && p.y >= 745 && p.y <= 805)
{mode = 1;
tast_litere();
}
else if(p.x >= 280 && p.x <= 595 && p.y >= 830 && p.y <= 895)
Serial.print(" ");
else if(p.y >= 610 && p.y <= 660)
{
if(p.x >= 160 && p.x <= 215)
Serial.print('1');
else if(p.x >= 220 && p.x <= 275)
Serial.print('2');
else if(p.x >= 280 && p.x <= 335)
Serial.print('3');
else if(p.x >= 340 && p.x <= 395)
Serial.print('4');
else if(p.x >= 400 && p.x <= 455)
Serial.print('5');
else if(p.x >= 460 && p.x <= 515)
Serial.print('6');
else if(p.x >= 520 && p.x <= 575)
Serial.print('7');
else if(p.x >= 580 && p.x <= 635)
Serial.print('8');
else if(p.x >= 640 && p.x <= 695)
Serial.print('9');
else if(p.x >= 700 && p.x <= 755)
Serial.print('0');
}
else if(p.y >= 680 && p.y <= 730)
{
if(p.x >= 160 && p.x <= 215)
Serial.print('@');
else if(p.x >= 220 && p.x <= 275)
Serial.print('#');
else if(p.x >= 280 && p.x <= 335)
Serial.print('$');
else if(p.x >= 340 && p.x <= 395)
Serial.print('_');
else if(p.x >= 400 && p.x <= 455)
Serial.print('&');
else if(p.x >= 460 && p.x <= 515)
Serial.print('-');
else if(p.x >= 520 && p.x <= 575)
Serial.print('+');
else if(p.x >= 580 && p.x <= 635)
Serial.print('(');
else if(p.x >= 640 && p.x <= 695)
Serial.print(')');
else if(p.x >= 700 && p.x <= 755)
Serial.print('/');
}
else if(p.y >= 750 && p.y <= 800)
{
if(p.x >= 185 && p.x <= 240)
Serial.print('*');
else if(p.x >= 245 && p.x <= 300)
Serial.print("'");
else if(p.x >= 305 && p.x <= 360)
Serial.print(':');
else if(p.x >= 365 && p.x <= 420)
Serial.print(';');
else if(p.x >= 425 && p.x <= 480)
Serial.print('!');
else if(p.x >= 485 && p.x <= 540)
Serial.print('?');
else if(p.x >= 545 && p.x <= 600)
Serial.print('=');
else if(p.x >= 605 && p.x <= 660)
Serial.print('%');
}
}
}
delay(200);
}