Go Down

Topic: New TFT Extension Library (Read 16348 times) previous topic - next topic

ikravets

Thanks a lot for your job!

Can you share this library on https://github.com, then I will add it to PlatformIO Library Register.

HazardsMind

I am in the process of setting up a Github account but I dont know how to use Github.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories


HazardsMind

I guess I did it.

https://github.com/AndrewMascolo/The-Libraries-I-use/
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

ikravets

#79
Oct 08, 2014, 10:19 am Last Edit: Oct 08, 2014, 03:24 pm by ikravets Reason: 1
Looks great for beginning! But CVS(like, SVN, GIT) was developed for keep track of all work and all changes in a set of files. This isn't good practice to keep in repository source that was packed in archive.

I recommend to create for each library separated repository with detailed information about it inside README.md file. See TOP examples by "arduino library" search query on GitHub:

  • https://github.com/shirriff/Arduino-IRremote

  • https://github.com/interactive-matter/aJson


and etc.

In your case the list of repositories:

  • Arduino-OneWireKeypad

  • Arduino-SeeedTouchScreen_V2

  • Arduino-SerialServo



and etc..

P.S: Which OS type do you use?


HazardsMind

This is the first time I have ever used Github and it is not straight forward or easy at all, so I'm surprised I was able to post anything.

Quote
recommend to create for each library separated repository with detailed information about it inside README.md file. See TOP examples by "arduino library" search query on GitHub:

I will look into that.

I am using Windows 8.1
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

robsworld78

Hi, nice library you've created, thanks for sharing. I'm interested in using the vertical slider but I'm using a 5" display and having troubles. When I load the example it shows 3 bars on the display with a box. The touch isn't working on the actual sliders, to move them I need to touch other areas of the screen and instead of sliding vertically I have to slide horizontally? The square box does show the color mix like it should.

I opened the .cpp file and saw the display resolution, I changed it to 800x480 but that doesn't seem to affect it any.

Do you have any idea?

HazardsMind

#82
Oct 24, 2014, 09:09 pm Last Edit: Oct 27, 2014, 05:43 pm by HazardsMind
Do you know if your touchscreen calibrated correctly? What screen orientation are you using and is it the same for the UTFT, UTouch and my library's setting?

Try this code and see if the values make sense. (Be sure to change the constructors)
Code: [Select]
#include <UTFT.h>
#include <UTouch.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];

//myGLCD(RS,WR,CS,RST,ALE,mode);
UTFT myGLCD(ITDB32S,A1,A2,A0,A3,A5);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
UTouch  myTouch(13,10,11,12,A4);

void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_LOW);
  myGLCD.fillScr(0,0,0);
  }

void loop()
{
  myTouch.read();
  Debug(myTouch.getX(), myTouch.getY());  
}

void Debug(int X, int Y)
{
  myGLCD.setBackColor(0, 0, 0);//background of text is black
  myGLCD.setColor(255,255,255); // test color is white

  myGLCD.print("X: ", 0,0, 0);
  if(X < 100){
    myGLCD.print("  ", 29,0, 0);
    myGLCD.printNumI(X, 24, 0);
  }
  else myGLCD.printNumI(X, 24, 0);

  myGLCD.print("Y: ", 55,0,0);
  if(Y < 100){
    myGLCD.print("  ", 84,0, 0);
    myGLCD.printNumI(Y, 79, 0);
  }
  else myGLCD.printNumI(Y, 79, 0);
}
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

HazardsMind

UPDATE Version 1.3

Fixed keyboard color, added a few new functions for the Latch(Button/Circle/Triangle)_Draw functions. Now you can set/reset the state of the latch buttons to a specific state -> PRESSED or RELEASED. (Suggestion from No1Daemon)

ResetLatchButtonState   
ResetAllLatchButtonState
   
ResetLatchCircleState   
ResetAllLatchCircleState
   
ResetLatchTriangleState
ResetAllLatchTriangleState   

See Latching Buttons example sketch.

Updated Constructor to just TFT_Extension myTFT(&myGLCD, &myTouch);, No need for landscape or portrait.

Added new Initializer function, myTFT.ExtSetup(); This will take care of the display size and orientation.

Fixed color pallet from RGB to 565 format.

As always, if you have an idea you want to add, let me know and I will be happy to add it. :)
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

  Hello, I am building a home automation system with a 4,3" TFT LCD screen and i am having a wonderful time coding the visuals of the system with your library, but i have a few questions.

  The main one is how i would go about making a custom shaped button, as for what i am designing i really need to figure out how to do this.

  What i want to do is make a square button, accept the lower left hand corner of the button is cut off and there is a diagonal line instead. I really need the diagonal to start about 30 pixels back on both lines, then connect the two together.

The total button size is 145px long and 75px tall. Thanks, Isaac N.

HazardsMind

You could just draw the shape and use TouchButton, not TouchButton_Draw.
TouchButton will work like TouchButton_Draw, but you wont see the button change colors when pressed.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

The main issue that i am having is that i can not figure out how to draw the general shape, never the less make it into a button.

HazardsMind

You would need to make your own functions to do custom shapes.

Something like this. (Untested)
Code: [Select]
void customShape(int x, int y, int w, int h, int Cx1, int Cy1, int Cx2, int Cy2, word Color)
{
  float slope = (Cx2 - Cy1) / (Cy2 - Cy1);
 
  for (int Dy = y; Dy < y + h; Dy++)
  {
    myGLCD.setColor(Color);
    if (Dy < Cy1)
      myGLCD.drawLine(x, Dy, x + w, Dy);
    else
    {
      myGLCD.drawLine(x + slope * Dy, Dy, x + w, Dy);
    }
  }
}
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

HazardsMind

Update to password sketch.

Password can be any length within the range of an unsigned long variable and pressing * or # will test the password as either PASS or FAIL.

Code: [Select]
#include <UTFT.h>
#include <UTouch.h>
#include <TFT_Extension.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

//myGLCD(RS,WR,CS,RST,ALE,mode);
UTFT myGLCD(ITDB32S, A1, A2, A0, A3, A5);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
UTouch  myTouch(13, 10, 11, 12, A4);
TFT_Extension myTFT(&myGLCD, &myTouch);

//For using the older ITDB02 libraries
//
//#include <ITDB02_Graph16.h>
//#include <ITDB02_Touch.h>
//#include <TFT_Extension_old.h>
//// Declare which fonts we will be using
//
//extern uint8_t SmallFont[];
//extern uint8_t BigFont[];
////myGLCD(RS,WR,CS,RST,ALE,mode);
//ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);
////myTouch(TCLK,TCS,DIN,DOUT,IRQ);
//ITDB02_Touch  myTouch(13,10,11,12,A4);
//TFT_Extension_old myTFT(&myGLCD, &myTouch);

char * PassText[4][3] = {
  {"1", "2", "3"},
  {"4", "5", "6"},
  {"7", "8", "9"},
  {"*", "0", "#"}
};

unsigned long MasterPassword = 2651; // can be any length within the range of an unsigned long variable

void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_EXTREME);
  myTFT.ExtSetup();
  for (int line = 0; line <= 239; line++) // custom background color
  {
    myGLCD.setColor(0, 0, line);//text color White
    myGLCD.drawLine(0, line, 319, line);
  }
  PassWord_makeButton();
  PassWord_buttonText();
}

void loop()
{
  GetPassword();
}

void PassWord_makeButton()
{
  for (int y = 0; y < 300; y += 100)
  {
    for (int x = 0; x < 200; x += 50)
    {
      drawButton(20 + x, 90 + y, 50 + x, 30 + y); // this will draw the button on the screen by so many pixels
    }
  }
  return;
}

void drawButton(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(170, 170, 170); // grey
  myGLCD.fillRoundRect(y1 - 3, x1 + 3, y2 - 3, x2 + 3); //Button Shading

  myGLCD.setColor(255, 255, 255); // white
  myGLCD.fillRoundRect(y1, x1, y2, x2);// outter button color

  myGLCD.setColor(200, 0, 0); // red
  myGLCD.fillRoundRect(y1 - 5, x1 + 5, y2 + 5, x2 - 5); //inner button color
  return;
}

void PassWord_buttonText()
{
  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(200, 0, 0);
  myGLCD.setColor(255, 255, 255);
  for (int tr = 0; tr < 300; tr += 100)
  {
    for (int tc = 0; tc < 200; tc += 50)
    {
      char *myText = PassText[tc / 50][tr / 100];
      myGLCD.print(myText, 52 + tr, 27 + tc, 0); //this will print the number into the center of the buttons
    }
  }
}

void GetPassword()
{
  bool PassFound = false, P_lock[12] = {false};
  unsigned long password = 0;
  byte i = 0;
 
  while (PassFound == false)
  {
    for (int tr = 0; tr < 300; tr += 100)
    {
      for (int tc = 0; tc < 200; tc += 50)
      {
        if ( i < 12)
        {
          if (myTFT.TouchButton((90 + tr), (20 + tc), (30 + tr), (50 + tc)) && P_lock[i] == false) // this check to see if any of the buttons were pressed, then it sends the corresponding number to the "check" function
          {
            if (strcmp(PassText[tc / 50][tr / 100], "*") && strcmp(PassText[tc / 50][tr / 100], "#")) // pressing * or # will test the entered password
            {
              password = (password * 10) + ((PassText[tc / 50][tr / 100])[0]) - '0';
              myGLCD.printNumI(password, CENTER, 1); // show the password as it is being entered
              P_lock[i] = true;
            }
            else
            {
              PassFound = checkPassword(2651);
              password = 0;
              delay(1000);
              myGLCD.print("    ", CENTER, 1);
            }
          }
          else
            P_lock[i] = false;
          i++;
        }
        else
          i = 0;
      }
    }
  }
}

bool checkPassword(unsigned long P)
{
  bool PF = false;
  if (P == MasterPassword)
  {
    myGLCD.print("GOOD", CENTER, 1);
    delay(1000);
    myGLCD.print("    ", CENTER, 1);
    PF = true;
  }
  else
  {
    myGLCD.print("FAIL", CENTER, 1);
    delay(1000);
    myGLCD.print("    ", CENTER, 1);
  }

  return PF;
}


BTW, I am still working on the new library, TFTExtensionV2. 
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

HazardsMind

Simple Calculator:


Code: [Select]
#include <UTFT.h>
#include <UTouch.h>
#include <TFT_Extension.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

//myGLCD(RS,WR,CS,RST,ALE,mode);
UTFT myGLCD(ITDB32S, A1, A2, A0, A3, A5);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
UTouch  myTouch(13, 10, 11, 12, A4);
TFT_Extension myTFT(&myGLCD, &myTouch);

//#include <ITDB02_Graph16.h>
//#include <ITDB02_Touch.h>
//#include <TFT_Extension_old.h>
//// Declare which fonts we will be using
//
//extern uint8_t SmallFont[];
//extern uint8_t BigFont[];
////myGLCD(RS,WR,CS,RST,ALE,mode);
//ITDB02 myGLCD(A1, A2, A0, A3, A5, ITDB32S);
////myTouch(TCLK,TCS,DIN,DOUT,IRQ);
//ITDB02_Touch  myTouch(13, 10, 11, 12, A4);
//TFT_Extension_old myTFT(&myGLCD, &myTouch);

const byte ROWS = 4;
const byte COLS = 4;

char * keys[ROWS][COLS] = {
  {"1", "2", "3", "+"},
  {"4", "5", "6", "-"},
  {"7", "8", "9", "x"},
  {"C", "0", "=", "/"}
};

byte i = 0, N = 0;
char Type = 0;
bool lock = false, P = false;
long num[2] = {0};
float total = 0;
char Op = ' ';

char Values[20];

void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_LOW);
  myTFT.ExtSetup();
  for (int line = 0; line <= 239; line++) // custom background color
  {
    myGLCD.setColor(0, 0, line);//text color White
    myGLCD.drawLine(0, line, 319, line);
  }
  Calculator_makeButton();
  Calculator_buttonText();
}

void loop()
{
  Calculator();
}

void Calculator_makeButton()
{
  for (int x = 0; x < 300; x += 75)
  {
    for (int y = 0; y < 200; y += 50)
    {
      drawButton(75 + x, 40 + y, 15 + x, 70 + y); // this will draw the button on the screen by so many pixels
    }
  }
  return;
}

void drawButton(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(170, 170, 170); // grey
  myGLCD.fillRoundRect(x1 - 3, y1 + 3, x2 - 3, y2 + 3); //Button Shading

  myGLCD.setColor(255, 255, 255); // white
  myGLCD.fillRoundRect(x1, y1, x2, y2);// outter button color

  myGLCD.setColor(200, 0, 0); // red
  myGLCD.fillRoundRect(x1 - 5, y1 + 5, x2 + 5, y2 - 5); //inner button color
  return;
}

void Calculator_buttonText()
{
  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(200, 0, 0);
  myGLCD.setColor(255, 255, 255);

  for (int tr = 0; tr < 300; tr += 75)
  {
    for (int tc = 0; tc < 200; tc += 50)
    {
      char *myText = keys[tc / 50][tr / 75];
      myGLCD.print(myText, 36 + tr, 47 + tc, 0); //this will print the number into the center of the buttons
    }
  }
}

void Calculator()
{
  myGLCD.setBackColor(BLACK);
  for (int tr = 0; tr < 300; tr += 75)
  {
    for (int tc = 0; tc < 200; tc += 50)
    {
      if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && !strcmp((keys[tc / 50][tr / 75]), "=") ) // Check for equal sign is pressed
      {
        switch (Type)
        {
          case 0: total = num[0] + num[1]; break;
          case 1: total = num[0] - num[1]; break;
          case 2: total = num[0] * num[1]; break;
          case 3: total = num[0] / num[1]; break;
        }
        Type = -1;

        //Tft.fillRectangle(0, 30, 50, 20, BLACK);
        myGLCD.setColor(WHITE);
        myGLCD.printNumI(total, CENTER, 18);
        delay(500);
        num[0] = 0;
        num[1] = 0;
        total = 0;
        N = 0;
        Op = ' ';
      }

      if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && !lock && ((tr / 75) != 3)) // make sure no operator is stored as a number
      {
        myGLCD.setColor(BLACK);
        //myGLCD.fillRect(0, 0, 239, 20);
        if (strcmp(keys[tc / 50][tr / 75], "C") && strcmp(keys[tc / 50][tr / 75], "=") ) // get numbers while they are not the equal sign
        {
          num[N] = (num[N] * 10) + ((keys[tc / 50][tr / 75])[0]) - '0';
          myGLCD.setColor(WHITE);
          //myGLCD.printNumI(num[N],0, 1);
          lock = true;

        }
      }
      if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && ((tr / 75) == 3) )//check for an operator
      {
        Type = (tc / 50);
        switch (Type)
        {
          case 0: Op = '+'; break;
          case 1: Op = '-'; break;
          case 2: Op = '*'; break;
          case 3: Op = '/'; break;
        }
        //C_buttons[i].setForeColor(RED);
        N = 1;

      }
      else
      {
        lock = false;
      }

      if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && !strcmp(keys[tc / 50][tr / 75], "C"))//clear the screen
      {
        for (int line = 0; line <= 35; line++) // custom background color
        {
          myGLCD.setColor(0, 0, line);//text color White
          myGLCD.drawLine(0, line, 319, line);
        }
      }

      sprintf(Values, "%ld %c %ld", num[0], Op, num[1]);
      myGLCD.setColor(WHITE);
      myGLCD.print(Values, 0, 1);
    }
  }
}
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy