Dedicated TFT controller

Hello again all! I have an old Sainsmart 320x240 TFT screen and I’m using the UTFT libraries. I wish to use the screen and Sainsmart MEGA as a dedicated LCD and touchscreen device that simply outputs text and shapes as directed by another Arduino.

Here’s the general, simplified idea:

#include <UTFT.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

UTFT myGLCD(ITDB32S,38,39,40,41); 

void setup()
{
  Serial1.begin(115200); 
// Setup the LCD
  myGLCD.InitLCD();
  myGLCD.clrScr();
  
}


void loop(){
  int LCDdisplayArray[]={0 /*colorRed[0]*/, 255 /*colorGreen[1]*/, 8 /*colorBlue[2]*/, 0 /*shape/text[3]*/, 10 /*x1[4]*/, 10 /*y1[5]*/, 100 /*x2[6]*/, 100 /*y2[7]*/, 50 /*radius[8]*/, 0 /*clearScreen[9]*/, 0 /*text font[10]*/, 0 /*text justification[11]*//*, 0 text[12]*/, 0 /*Rotation[13]*/, 1 /*Lanadscape/Portrait[14]*/};//Recieve Data from Master
                                                                             //Shape: 0=line, 1=Rect, 2=fillRect, 3= circ, 4=fillCirc, 
                                                                             //5=roundRect 6=text 7=pixel, 8=round Rect 

  int colorR=LCDdisplayArray[0];
  int colorG=LCDdisplayArray[1];
  int colorB=LCDdisplayArray[2];
  int shape = LCDdisplayArray[3];
  int x1= LCDdisplayArray[4];
  int y1= LCDdisplayArray[5];
  int x2= LCDdisplayArray[6];
  int y2= LCDdisplayArray[7];
  int radius= LCDdisplayArray[8];
  int clearScreen= LCDdisplayArray[9];
  int textFont= LCDdisplayArray[10];
  int textJustification= LCDdisplayArray[11];
  int text= LCDdisplayArray[12];
  int rotation= LCDdisplayArray[13];
  int landscapeOrPortrait= LCDdisplayArray[14];
  
  switch(landscapeOrPortrait){
    case 1:
      myGLCD.InitLCD(LANDSCAPE);
    break;
    
    case 2:
      myGLCD.InitLCD(PORTRAIT);
    break;
  }
  myGLCD.setColor(colorR,colorG,colorB);
  switch(shape){
    case 0:
      myGLCD.drawLine(x1,y1,x2,y2);
    break;
    case 1:
      myGLCD.drawRect(x1,y1,x2,y2);
    break;
    
    case 2:
      myGLCD.fillRect(x1,y1,x2,y2);
    break;
    
    case 3:
      myGLCD.drawCircle(x1,y1,radius);
    break;
    
    case 4:
      myGLCD.fillCircle(x1,y1,radius);
    break;
    
    case 5:
      myGLCD.fillRoundRect(x1,y1,x2,y2);
    break;
   
    case 6:
      switch(textFont){
        case 0:
          myGLCD.setFont(BigFont);
        break;
  
        case 1:
          myGLCD.setFont(SevenSegNumFont);
        break;
        
        case 2:
          myGLCD.setFont(SmallFont);
        break;
    }
    case 7:
      myGLCD.drawPixel(x1,y1);
    break;
    
    case 8:
      myGLCD.drawRoundRect(x1,y1,x2,y2);
    break;
  }
  if(clearScreen==1){
    myGLCD.clrScr(); 
  }
}

Data comes in off the Serial line and is placed into an array (we’ll assume that works fine). The data is information for the LCD to print. Shapes, colors, and coordinates have proven easy to handle but I need text too. The UTFT command for printing text is

myGLCD.print(“TEXT”, justification, Ycoordinate, rotationAngle)

Any ideas how to make my array setup able to print text from an array according to the UTFT syntax? This is still rough code, hope it gives you an idea of what I’m going for

Ok after doing some research I've realized that it's basically a question of how to turn an integer into a character. the UTFT syntax accepts

String string="";

myGLCD.print(string, CENTER, 10, 0);

So. I don't often work with strings in Arduino, how is this done?

Don't use String, instead use C strings. Put the integer into a char array, and print the array.

This is a function that does just that.

void TFT_Extension::ReceiveMsg(int X, int Y, byte R, byte G, byte B)
{
~~ #if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)~~
if(Serial1.available() > 0)
{
~~ if(!RCV_locked)~~
~~ {~~
~~ clearRCVMSG();~~
~~ _Disp->print(ReceiveMSG,X,Y);~~
~~ RCV_locked = true;~~
~~ }~~
char R_MSG = Serial1.read(); // read in each char from serial ie bluetooth module
if( R_MSG != '\n') // if the incoming char is not '\n' (NewLine)
{
ReceiveMSG[RCV_cnt] = R_MSG; // store the char in the array
RCV_cnt++; // increment array index by 1
}
else // the incoming char was '\n'
{
_Disp->setColor(R,G,B); // set the color of the text
_Disp->print(ReceiveMSG,X,Y); // print the array at X,Y
RCV_cnt=0; // reset index count back to 0 for new text
RCV_locked = false;
}
}
#endif
}

I have to use String the syntax for

myGLCD("TEXT",CENTER,y,rotation);

requires a String in place of the "TEXT" argument. Doesn't accept Char.

So I need to read a number out of an array then somehow convert it to a string to show text. I know that decimal 65 is "A", how might I go about converting a 65 found in an array to a string value I can print on screen?

myGLCD("TEXT",CENTER,y,rotation);

It will print a char array, I know this because I too use that library. The function I gave is from my own library that works with UTFT.

Do this, and see if it prints.

char myMSG = "Hello";
myGLCD.print(myMSG,CENTER,y,rotation);

I know that decimal 65 is "A", how might I go about converting a 65 found in an array to a string value I can print on screen?

Use myGLCD.printNumI for integers and .printNumF for floats.

Added:
If you look at the UTFT library, you will see two versions of the .print function. One is for char pointers, and the other is for, yes, Strings.

OK thanks I get it now.

When I'm using stings, the correct syntax is:

String string="Hello World";

myGLCD.print(string[0], CENTER, y, rotation);

The correct way to use a char array in this method is

char charArray="Hello World";

myGLCD(charArray, CENTER, y, rotation);

I was doing this:

char charArray="Hello World";

myGLCD(charArray[0], CENTER, y, rotation);

because I thought the syntax was the same as String. this incorrect method was causing strange error messages about pointers. I may not fully understand what is wrong but I now know the correct syntax and I can work with that.

Thank you for the help good sir! May a large group of individuals bearing good tidings find their way to you by day's end!

May a large group of individuals bearing good tidings find their way to you by day's end!

:astonished: Wow, I have never had that said to me, Thank you and likewise.