Pages: [1]   Go Down
Author Topic: 3.2" TFT with UTFT  (Read 713 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to create a menu system for my brewery that i am building but i am having trouble with a button. I find that if i press the button that shares the same location of a submenu button it presses it straight after i have pressed it on the main menu. This is only happening for the Menu button on the main menu.


Here is my code.
Any help would be most appreciated.

Code:
#include <UTFT.h>
#include <UTouch.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS 8
float HLTtemp; //0x28, 0xEE, 0x6D, 0x34, 0x05, 0x00, 0x00, 0xAA
float Mashtemp; //0x28, 0x48, 0x27, 0x35, 0x05, 0x00, 0x00, 0x9F
float Boilertemp; //0x28, 0x25, 0x28, 0x35, 0x05, 0x00, 0x00, 0x79
DeviceAddress HLT = { 
  0x28, 0xEE, 0x6D, 0x34, 0x05, 0x00, 0x00, 0xAA };
DeviceAddress Mash = { 
  0x28, 0x48, 0x27, 0x35, 0x05, 0x00, 0x00, 0x9F };
DeviceAddress Boiler = {
  0x28, 0x25, 0x28, 0x35, 0x05, 0x00, 0x00, 0x79 };
 
  OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

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


int x, y,g,menu;

UTFT          myGLCD(ITDB32S,38,39,40,41);
UTouch        myTouch(6,5,4,3,2);


void setup()
{
  sensors.begin();
  myGLCD.InitLCD(LANDSCAPE);                   // Initialize the display
  myGLCD.clrScr();                             // Clear the screen (black)
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_MEDIUM);
  myGLCD.setFont(BigFont);
  myGLCD.fillScr(255,255,255);               // Clear the screen (White)
  delay(600);                                 //Delay to draw the image
  myGLCD.clrScr();                            // Clear the screen (black)
  Menu1();
  menu=1;
}

void readtemp()
{
  //Call sensors.requestTemperatures() to issure a global temperature
  //request to all devices on the bus
  sensors.requestTemperatures(); //Send the command to get temperatures
  HLTtemp = (sensors.getTempC(HLT));
  Mashtemp = (sensors.getTempC(Mash));
  Boilertemp = (sensors.getTempC(Boiler));
}

//Buttons coordinates
//Menu 1
//Button HLT
int x11=20; int y11=20; int x12=150; int y12=100;
//Button Mash
int x21=180; int y21=20; int x22=300; int y22=100;
//Button Boiler
int x31=20; int y31=120; int x32=150; int y32=200;
//Button Menu
int x41=180; int y41=120; int x42=300; int y42=200;
//Button G
int x51=10; int y51=10; int x52=160; int y52=220;
//Button Back
int x61=200; int y61=130; int x62=300; int y62=220;
//Front led
int x71=20; int y71=40; int x72=170; int y72=100;
//Back led
int x81=20; int y81=130; int x82=170; int y82=190;

void Menu1()    // MAIN MENU
{
  myGLCD.clrScr(); // Clear the screen (black)
  myGLCD.setFont(BigFont);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 255);
  //BUTTON Gpro
  button (x11,y11,x12,y12);  myGLCD.print("HLT",35,50);
  //BUTTON Leds
  button (x21,y21,x22,y22);  myGLCD.print("Mash",210,50);   
  //BUTTON Volto
  button (x31,y31,x32,y32);  myGLCD.print("Boiler",35,150);     
  //BUTTON Spare
  button (x41,y41,x42,y42);  myGLCD.print("Menu",210,150);

  menu =1; 
 
 
}

void Menu2()    //HLT MENU
{
   myGLCD.clrScr(); // Clear the screen (black)
  myGLCD.print("HLT Temp:", 20, 20);
  myGLCD.setBackColor(0, 0, 255);
  button (x61,y61,x62,y62);   myGLCD.setFont(BigFont);  myGLCD.print("Back",230,200);   
  menu =2;
  myGLCD.printNumF(HLTtemp, 1, 200, 20);
}

void Menu3()    //Mash MENU
{

  myGLCD.clrScr(); // Clear the screen (black)
  //Front led
  button (x71,y71,x72,y72);
  myGLCD.setFont(BigFont);    myGLCD.print("Front Led",30,70);
  //Back Led
  button (x81,y81,x82,y82);
  myGLCD.setBackColor(0, 0, 255);
  myGLCD.setFont(BigFont);    myGLCD.print("Back Led",30,160);   
  button (x61,y61,x62,y62);   myGLCD.setFont(BigFont);  myGLCD.print("Back",230,200);   
  menu =3;

}

void Menu4()    // MENU 4
{

  myGLCD.clrScr(); // Clear the screen (black)
  myGLCD.setFont(BigFont);    myGLCD.print("Menu 4",30,70);
  button (x61,y61,x62,y62);   myGLCD.setFont(BigFont);  myGLCD.print("Back",230,200);   
  menu =4;

}

void Menu5()    // MENU 5
{

  myGLCD.clrScr(); // Clear the screen (black)
 
  myGLCD.setFont(BigFont);     myGLCD.print("Menu 5",30,70);
  button (x61,y61,x62,y62);   myGLCD.setFont(BigFont);  myGLCD.print("Back",230,200);   
  menu =5;

}



void loop()
{
  while (true)
  {
    if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();

      if (menu ==1) 
      {
        if ((y>=y11) && (y<=y12))  // Upper row
        {     
          if ((x>=x11) && (x<=x12))  // Button: Gpro
          {       
            waitForIt(x11,y11,x12,y12);
            menu =2;
            Menu2();
          }
          if ((x>=x21) && (x<=x22))  // Button: Leds
           {
             waitForIt(x21,y21,x22,y22);
            menu =3;
            Menu3();
           }
        }
        if ((y>=y31) && (y<=y32))  // Lower row
        {     
          if ((x>=x31) && (x<=x32))  // Button: Volto
           {
             waitForIt(x31,y31,x32,y32);
           menu =4;
           Menu4();
           }
          if ((x>=x41) && (x<=x42))  // Button: Spare
           {
             waitForIt(x41,y41,x42,y42);
             menu =5;
             Menu5();
             
           }
        }
      }

      if (menu==2)
      {
       
        myGLCD.setFont(BigFont);
              delay(300);
        if ((y>=y61) && (y<=y62))  // Button: Back
        {     
          if ((x>=x61) && (x<=x62))  // Button: Back
          {     
            waitForIt(x61,y61,x62,y62);
            menu =1;
            Menu1();
          }

        }
      }
      if (menu==3)
      {
        delay(300);
        if ((y>=y61) && (y<=y62))  // Button: Back
        {     
          if ((x>=x61) && (x<=x62))  // Button: Back
          {     
            waitForIt(x61,y61,x62,y62);
            menu =1;
            Menu1();
          }

        }
      }
            if (menu==4)
      {
        if ((y>=y61) && (y<=y62))  // Button: Back
        {     
          if ((x>=x61) && (x<=x62))  // Button: Back
          {     
            waitForIt(x61,y61,x62,y62);
            menu =1;
            Menu1();
          }

        }
      }
            if (menu==5)
      {
        if ((y>=y61) && (y<=y62))  // Button: Back
        {     
          if ((x>=x61) && (x<=x62))  // Button: Back
          {     
            waitForIt(x61,y61,x62,y62);
            menu =1;
            Menu1();
          }

        }
      }
   
    }
}
}


void button(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (x1,y1,x2,y2);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1,y1,x2,y2);
}

// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  //while (myTouch.dataAvailable())
  //myTouch.read();
  delay(300);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}

« Last Edit: September 26, 2013, 02:53:03 pm by oakey22 » Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't look through your whole code but basically, yes, that's the way UTFT_Buttons works. You need to disable the buttons that are not part of the current menu, then re-enable them when that menu becomes the top menu.
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not using UTFT_Buttons in the menu, if this becomes a problem that i can not solve i will have to not put buttons where the previous ones are, but there must be a way?
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, well in that case the problem is UTouch returns dataAvailable() == true while a portion of the screen is pressed. You need to loop while data is available() == true (i.e.: detect the finger being lifted off the screen) before processing more buttons.

something like:

while (1)
{
    if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();

      // process key here
     
      while (myTouch.dataAvailable())
             ; // wait here until they've lifted their finger
    }

Logged

Do not IM me. I will not respond. Ask questions in the forum.

Pages: [1]   Go Up
Jump to: