Go Down

Topic: 2.8 tft ILI9325 touch menu's? (Read 5229 times) previous topic - next topic

thecomputerguy

Hi I'm using a 2.8 tft ILI9325 touch screen with a arduino mega and RGB LEDs.

I have build a sweet PC fan controller with touch menu. All is well in that department.

But I've added RGB LEDs to the mix. So what I'm trying to figure out is there a way i can put a button on the screen that will change the
menu (i.e for RGB control) then push done button to go back to fan control screen. <- this will be easy enough just screenfill then rebuild.)

The part I think I can't seem to figure out how to code it to change the touch screen input area when menu changes.

I've searched pretty hard and havn't found much. Can anyone direct me somewhere that has tried this with any code examples. Or offer some input.

Would making one touch area a (not sure what it's called but) void function:
Void firstmenu()
{ blah blah touch areas do this etc..
}
http://www.youtube.com/watch?v=CuLpFTlA1Wg





thecomputerguy

Has anyone done a menu with this screen from adafruit?
http://www.adafruit.com/index.php?main_page=product_info&cPath=37&products_id=335

I do have a sdcard for it as well. I'm just tring to figure it out.

Where can i look who can i ask Anyone?

AndreMion

:D aonde eu encontro este menu?
estou construindo um projeto de Water Cooling com assistência de pastilhas de Peltier. Seria bem útil este menu!  8)

Docedison

I was thinking to use the edge middles and corners to point up/down right/left and diagonals for a 9 page menu and I had an idea for vector position location that I am going to try to write this month. I have 2 of the 3.2" displays from Electrodrogon (@17.00 ea US) W/o shield for a mega (6.00 more) and I will need at least 4 menu's. I'll try to post my results.

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

urthlight

#4
Dec 06, 2012, 02:03 am Last Edit: Dec 06, 2012, 02:22 am by urthlight Reason: 1
I think I have the same display from electrodragon. I bought them as backups while the adafruit displays were on back order. But then we got the last two 2.8 TFTs from Ada. So in a week or so I will try my hand at the cheap ones.
However I did find this
Code: [Select]


/**
* Touch Control Panel
* Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
* Copyright 2009 Hugh Blemings <hugh@blemings.org>
*
* Reads touch coordinates on a Nintendo DS touch screen attached to an
* Arduino and compares them to defined hot zones representing buttons
* and sliders. If a touch occurs within a hot zone a matching event
* message is sent to the host via the serial port.
*
* Based on the ReadTouchscreen example included in the TouchScreen
* library.
*
*   www.practicalarduino.com/projects/touch-control-panel
*/
#include <TouchScreen.h>

TouchScreen ts(3, 1, 0, 2);

void setup()
{
  Serial.begin(38400);
}

void loop()
{
  int coords[2];
  ts.read(coords);
  Serial.print(coords[0]);
  Serial.print(",");
  Serial.print(coords[1]);

  if((coords[0] > 696) && (coords[0] < 866)
  && (coords[1] > 546) && (coords[1] < 831)) {
    Serial.print(", Fan ON");
  }
  if((coords[0] > 696) && (coords[0] < 866)
  && (coords[1] > 208) && (coords[1] < 476)) {
    Serial.print(", Fan OFF");
  }
  if((coords[0] > 420) && (coords[0] < 577)
  && (coords[1] > 540) && (coords[1] < 866)) {
    Serial.print(", Drapes OPEN");
  }
  if((coords[0] > 420) && (coords[0] < 577)
  && (coords[1] > 208) && (coords[1] < 476)) {
    Serial.print(", Drapes CLOSE");
  }
  if((coords[0] > 139) && (coords[0] < 327)
  && (coords[1] > 208) && (coords[1] < 866)) {
    Serial.print(", Illumination:");
    Serial.print(constrain(map(coords[1], 318, 756, 0, 100), 0, 100));
    Serial.print("%");
  }

  Serial.println();
  delay (100);
}


Docedison

The UTFT library by Henning Karlsen will fix all of your issues, It (Data attached) directly supports your module and he has just released a New Utouch library that is nice, new and easy to use. It directly supports your touch module as does UTFT support your graphics module. I bought several (Until I found them on Amazon for $18.98 US AND a Much better warranty too) of the TFT_320QUT from Electrodragon and both worked very well with the UTFT lib But I could never get the touch working. With the Urtouch lib all works right.

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

rilas

Hi. I used the new UTouch library from http://www.henningkarlsen.com/electronics/library.php?id=55
Probably your module is supported and the i started modifying the UTouch_Button_test for testing

Currently im building a Touch menu interface so its not complete so far. Here is my code to get
an idea. 4 Button menu to get to sub menus and a Back button to return to main menu
so far only the 2 first buttons "do" something and only the "first" has some meaningful code behind
(later to read an input from live system)

Hope it will help u.

=========================================================================================================
#include <UTFT.h>
#include <UTouch.h>

// 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[];
extern unsigned int v[0x400];            //Image loaded as a sourche file (later to move to SD)

int x, y,g,menu;

UTFT myGLCD(ILI9325D_8,A5,A4,A3,A2);        //Screen initialization
UTouch    myTouch(A1,8,A0,9,10);         //Touch initialization

void setup()
{
  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)
  myGLCD.drawBitmap(40, 0, 80, 80, v,3);       // Draw a pixel bitmap
  delay(3000);                                 //Delay to draw the image
  myGLCD.clrScr();                            // Clear the screen (black)
  Menu1();
  menu=1;
}

//Buttons coordinates
//Menu 1
//Button Gpro
int x11=20; int y11=20; int x12=150; int y12=100;
//Button Leds
int x21=180; int y21=20; int x22=300; int y22=100;
//Button Volto
int x31=20; int y31=120; int x32=150; int y32=200;
//Button Spare
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("Gpro",35,50);
  //BUTTON Leds
  button (x21,y21,x22,y22);  myGLCD.print("Leds",210,50);   
  //BUTTON Volto
  button (x31,y31,x32,y32);  myGLCD.print("Volto",35,150);     
  //BUTTON Spare
  button (x41,y41,x42,y42);  myGLCD.print("Spare",210,150);
  menu =1; 
}

void Menu2()    //GPRO MENU
{
   myGLCD.clrScr(); // Clear the screen (black)
  //BUTTON Gpro
  button (x51,y51,x52,y52);
  //BUTTON Back
  myGLCD.setBackColor(0, 0, 255);
  button (x61,y61,x62,y62);   myGLCD.setFont(BigFont);  myGLCD.print("Back",230,200);   
  menu =2;
}

void Menu3()    //GPRO 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 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);
          if ((x>=x41) && (x<=x42))  // Button: Spare
            waitForIt(x41,y41,x42,y42);
        }
      }

      if (menu==2)
      {
        int g=random(6);
        myGLCD.setFont(SevenSeg_XXXL_Num);
        myGLCD.printNumI(g,35,50);
        delay(1000);
        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)
      {
        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);
}

=========================================================================================================

Go Up