Hello! I am looking for a on-screen keyboard program for my Elegoo 2.8inch TFT touch display. I am looking for something like this Adafruit TFT Touchscreen - Keypad for touchscreen?
but for elegoo tft touchscreen. Please keep in mind that i am using a UNO, so if possible pls make the sketch size smaller. Any help will be appreciated!
I edited the code a bit and here is what the code is:
#include <TouchScreen.h>
//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.
//
//Thanks to Adafruit forums member Asteroid for the original sketch!
//
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_TFTLCD.h>
//#include <Touchscreen.h>
static byte KB_Data;
// This is calibration data for the raw touch data to the screen coordinates
#define IsWithin(x, a, b) ((x>=a)&&(x<=b))
#define TS_MINX 142
#define TS_MINY 125
#define TS_MAXX 3871
#define TS_MAXY 3727
#define STMPE_CS 8
Adafruit_TFTLCD tft;
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 8 // can be a digital pin
#define XP 9 // can be a digital pin
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define TFT_CS 10
#define TFT_DC 9
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#include <avr/pgmspace.h>
const char Mobile_KB[3][13] PROGMEM = {
{0, 13, 10, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'},
{1, 12, 9, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'},
{3, 10, 7, 'Z', 'X', 'C', 'V', 'B', 'N', 'M'},
};
const char Mobile_NumKeys[3][13] PROGMEM = {
{0, 13, 10, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'},
{0, 13, 10, '-', '/', ':', ';', '(', ')', '$', '&', '@', '"'},
{5, 8, 5, '.', '\,', '?', '!', '\''}
};
const char Mobile_SymKeys[3][13] PROGMEM = {
{0, 13, 10, '[', ']', '{', '}', '#', '%', '^', '*', '+', '='},
{4, 9, 6, '_', '\\', '|', '~', '<', '>'}, //4
{5, 8, 5, '.', '\,', '?', '!', '\''}
};
const char textLimit = 25;
char MyBuffer[textLimit];
void MakeKB_Button(const char type[][13])
{
tft.setTextSize(2);
tft.setTextColor(0xffff, 0xf000);
for (int y = 0; y < 3; y++)
{
int ShiftRight = 15 * pgm_read_byte(&(type[y][0]));
for (int x = 3; x < 13; x++)
{
if (x >= pgm_read_byte(&(type[y][1]))) break;
drawButton(15 + (30 * (x - 3)) + ShiftRight, 100 + (30 * y), 20, 25); // this will draw the button on the screen by so many pixels
tft.setCursor(20 + (30 * (x - 3)) + ShiftRight, 105 + (30 * y));
tft.print(char(pgm_read_byte(&(type[y][x]))));
}
}
//ShiftKey
drawButton(15, 160, 35, 25);
tft.setCursor(27, 168);
tft.print('^');
//Special Characters
drawButton(15, 190, 35, 25);
tft.setCursor(21, 195);
tft.print(F("SP"));
//BackSpace
drawButton(270, 160, 35, 25);
tft.setCursor(276, 165);
tft.print(F("BS"));
//Return
drawButton(270, 190, 35, 25);
tft.setCursor(276, 195);
tft.print(F("RT"));
//Spacebar
drawButton(60, 190, 200, 25);
tft.setCursor(105, 195);
tft.print(F("SPACE BAR"));
}
void drawButton(int x, int y, int w, int h)
{
// grey
tft.fillRoundRect(x - 3, y + 3, w, h, 3, 0x8888); //Button Shading
// white
tft.fillRoundRect(x, y, w, h, 3, 0xffff);// outter button color
//red
tft.fillRoundRect(x + 1, y + 1, w - 1 * 2, h - 1 * 2, 3, 0xf800); //inner button color
}
void GetKeyPress(char * textBuffer)
{
char key = 0;
static bool shift = false, special = false, back = false, lastSp = false, lastSh = false;
static char bufIndex = 0;
if (!ts.bufferEmpty())
{
//ShiftKey
if (TouchButton(15, 160, 35, 25))
{
shift = !shift;
delay(200);
}
//Special Characters
if (TouchButton(15, 190, 35, 25))
{
special = !special;
delay(200);
}
if (special != lastSp || shift != lastSh)
{
if (special)
{
if (shift)
{
tft.fillScreen(BLUE);
MakeKB_Button(Mobile_SymKeys);
}
else
{
tft.fillScreen(BLUE);
MakeKB_Button(Mobile_NumKeys);
}
}
else
{
tft.fillScreen(BLUE);
MakeKB_Button(Mobile_KB);
tft.setTextColor(0xffff, 0xf800);
}
if (special)
tft.setTextColor(0x0FF0, 0xf800);
else
tft.setTextColor(0xFFFF, 0xf800);
tft.setCursor(21, 195);
tft.print(F("SP"));
if (shift)
tft.setTextColor(0x0FF0, 0xf800);
else
tft.setTextColor(0xffff, 0xf800);
tft.setCursor(27, 168);
tft.print('^');
lastSh = shift;
lastSp = special;
lastSh = shift;
}
for (int y = 0; y < 3; y++)
{
int ShiftRight;
if (special)
{
if (shift)
ShiftRight = 15 * pgm_read_byte(&(Mobile_SymKeys[y][0]));
else
ShiftRight = 15 * pgm_read_byte(&(Mobile_NumKeys[y][0]));
}
else
ShiftRight = 15 * pgm_read_byte(&(Mobile_KB[y][0]));
for (int x = 3; x < 13; x++)
{
if (x >= (special ? (shift ? pgm_read_byte(&(Mobile_SymKeys[y][1])) : pgm_read_byte(&(Mobile_NumKeys[y][1]))) : pgm_read_byte(&(Mobile_KB[y][1])) )) break;
if (TouchButton(15 + (30 * (x - 3)) + ShiftRight, 100 + (30 * y), 20, 25)) // this will draw the button on the screen by so many pixels
{
if (bufIndex < (textLimit - 1))
{
delay(200);
if (special)
{
if (shift)
textBuffer[bufIndex] = pgm_read_byte(&(Mobile_SymKeys[y][x]));
else
textBuffer[bufIndex] = pgm_read_byte(&(Mobile_NumKeys[y][x]));
}
else
textBuffer[bufIndex] = (pgm_read_byte(&(Mobile_KB[y][x])) + (shift ? 0 : ('a' - 'A')));
bufIndex++;
}
break;
}
}
}
//Spacebar
if (TouchButton(60, 190, 200, 25))
{
textBuffer[bufIndex++] = ' ';
delay(200);
}
//BackSpace
if (TouchButton(270, 160, 35, 25))
{
if ((bufIndex) > 0)
bufIndex--;
textBuffer[bufIndex] = 0;
tft.setTextColor(0, BLUE);
tft.setCursor(15, 80);
tft.print(F(" "));
delay(200);
}
//Return
if (TouchButton(270, 190, 35, 25))
{
KB_Data = textBuffer;
while (bufIndex > 0)
{
bufIndex--;
textBuffer[bufIndex] = 0;
}
tft.setTextColor(0, ILI9341_BLUE);
tft.setCursor(15, 80);
tft.print(F(" "));
}
}
tft.setTextColor(0xffff, 0xf800);
tft.setCursor(15, 80);
tft.print(textBuffer);
}
void setup(void)
{
}
void loop()
{
// See if there's any touch data for us
////GetKeyPress(MyBuffer);
}
byte TouchButton(int x, int y, int w, int h)
{
int X, Y;
// Retrieve a point
TS_Point p = ts.getPoint();
Y = map(p.x, TS_MINY, TS_MAXY, tft.height(), 0);
X = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
return (IsWithin(X, x, x + w) & IsWithin(Y, y, y + h));
}
void KB() {
//Serial4.begin(115200);
tft.begin();
if (!ts.begin())
tft.println(F("Unable to start touchscreen.(188.9)"));
else
tft.println(F("Touchscreen started.(401.6)"));
tft.fillScreen(BLUE);
// origin = left,top landscape (USB left upper)
tft.setRotation(1);
MakeKB_Button(Mobile_KB);
GetKeyPress(MyBuffer);
}
I then get a error:
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"
C:\Users\Charl\Downloads\Keyboard\Keyboard.ino: In function 'void GetKeyPress(char*)':
Keyboard:120:11: error: 'class TouchScreen' has no member named 'bufferEmpty'
if (!ts.bufferEmpty())
^~~~~~~~~~~
Keyboard:142:26: error: 'BLUE' was not declared in this scope
tft.fillScreen(BLUE);
^~~~
Keyboard:147:26: error: 'BLUE' was not declared in this scope
tft.fillScreen(BLUE);
^~~~
Keyboard:153:24: error: 'BLUE' was not declared in this scope
tft.fillScreen(BLUE);
^~~~
Keyboard:233:27: error: 'BLUE' was not declared in this scope
tft.setTextColor(0, BLUE);
^~~~
Keyboard:249:27: error: 'ILI9341_BLUE' was not declared in this scope
tft.setTextColor(0, ILI9341_BLUE);
^~~~~~~~~~~~
C:\Users\Charl\Downloads\Keyboard\Keyboard.ino: In function 'byte TouchButton(int, int, int, int)':
Keyboard:276:3: error: 'TS_Point' was not declared in this scope
TS_Point p = ts.getPoint();
^~~~~~~~
C:\Users\Charl\Downloads\Keyboard\Keyboard.ino:276:3: note: suggested alternative: 'TSPoint'
TS_Point p = ts.getPoint();
^~~~~~~~
TSPoint
Keyboard:277:11: error: 'p' was not declared in this scope
Y = map(p.x, TS_MINY, TS_MAXY, tft.height(), 0);
^
C:\Users\Charl\Downloads\Keyboard\Keyboard.ino: In function 'void KB()':
Keyboard:285:11: error: 'class TouchScreen' has no member named 'begin'
if (!ts.begin())
^~~~~
Keyboard:290:18: error: 'BLUE' was not declared in this scope
tft.fillScreen(BLUE);
^~~~
exit status 1
'class TouchScreen' has no member named 'bufferEmpty'
What happens when you run the original code?
Original code, it is for ADAFRUIT_ILI9341.
A different controller? What changes did you make to it, in your attempt to port it to the new display?
yes. i am assuming that if i change library it will work.
But of course you have to change all the library calls too... different libraries have different functions.
my main usage is to make a 'notepad' app and when i type it wil put it on the MicroSD card.
yes i changed it.
Changed what?
library call.
You can see that it failed. You need to consult the new library documentation for the right functions. The ones you're using don't exist in it. The compiler is telling you so.
this is my problem.
'class TouchScreen' has no member named 'bufferEmpty'
is there a duplicate function for BufferEmpty?
Why ask me? That is the exact kind of thing that is in the documentation I mentioned.
sorry if i am a bit pushy, as this is my first arduino project.
Sure, well the computer is agnostic about everyones feelings, it doesn't accept apologies...
can you pls give me documentation link?
Give you? If you're using a library, you should have it. At the moment it looks like you could look here:
#include <Adafruit_TFTLCD.h>
Adafruit website is known for great docs.
@lildashund1, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project See About the Installation & Troubleshooting category.