Boton de menu para pantalla tactil!!!

¿Hay alguien que tenga alguna simple aplicacion hecha con la libreria URtouch para leer un simple boton del touch 2.8 y saltar a una tarea??

Saludos

Gracias!

El propio ejemplo de la librería tiene un ejemplo con 3 botones

Si amigo ya lo se pero al correrlo me da un erro de compilacion y se queda ahi

Hay un error con la libreria ILI9341_due_Buttons.h

Saludos

Pero en tu post#1 nada dices de eso, pides un código y fue lo que te respondí.
Yo cuando uso la librería, no da errores.

Ahora, puede que estes usando una librería vieja.

De esta hablo yo URtouch.zip y de esta UTFT.zip corriendo este ejemplo

// URTouch_ButtonTest 
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program is a quick demo of how create and use buttons.
//
// This program requires the UTFT library.
//
// It is assumed that the display module is connected to an
// appropriate shield or that you know how to change the pin 
// numbers in the setup.
//

#include <UTFT.h>
#include <URTouch.h>

// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due       : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board                   : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!
UTFT    myGLCD(ITDB32S,38,39,40,41);

// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield            :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due       :  6, 5, 4, 3, 2
// Teensy 3.x TFT Test Board                   : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
URTouch  myTouch( 6, 5, 4, 3, 2);

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

int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";

/*************************
**   Custom functions   **
*************************/

void drawButtons()
{
// Draw the upper row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x*60), 10, 60+(x*60), 60);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x*60), 10, 60+(x*60), 60);
    myGLCD.printNumI(x+1, 27+(x*60), 27);
  }
// Draw the center row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x*60), 70, 60+(x*60), 120);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x*60), 70, 60+(x*60), 120);
    if (x<4)
      myGLCD.printNumI(x+6, 27+(x*60), 87);
  }
  myGLCD.print("0", 267, 87);
// Draw the lower row of buttons
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (10, 130, 150, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (10, 130, 150, 180);
  myGLCD.print("Clear", 40, 147);
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (160, 130, 300, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (160, 130, 300, 180);
  myGLCD.print("Enter", 190, 147);
  myGLCD.setBackColor (0, 0, 0);
}

void updateStr(int val)
{
  if (stCurrentLen<20)
  {
    stCurrent[stCurrentLen]=val;
    stCurrent[stCurrentLen+1]='\0';
    stCurrentLen++;
    myGLCD.setColor(0, 255, 0);
    myGLCD.print(stCurrent, LEFT, 224);
  }
  else
  {
    myGLCD.setColor(255, 0, 0);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    delay(500);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    myGLCD.setColor(0, 255, 0);
  }
}

// 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();
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}

/*************************
**  Required functions  **
*************************/

void setup()
{
// Initial setup
  myGLCD.InitLCD();
  myGLCD.clrScr();

  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);

  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  drawButtons();  
}

void loop()
{
  while (true)
  {
    if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
      
      if ((y>=10) && (y<=60))  // Upper row
      {
        if ((x>=10) && (x<=60))  // Button: 1
        {
          waitForIt(10, 10, 60, 60);
          updateStr('1');
        }
        if ((x>=70) && (x<=120))  // Button: 2
        {
          waitForIt(70, 10, 120, 60);
          updateStr('2');
        }
        if ((x>=130) && (x<=180))  // Button: 3
        {
          waitForIt(130, 10, 180, 60);
          updateStr('3');
        }
        if ((x>=190) && (x<=240))  // Button: 4
        {
          waitForIt(190, 10, 240, 60);
          updateStr('4');
        }
        if ((x>=250) && (x<=300))  // Button: 5
        {
          waitForIt(250, 10, 300, 60);
          updateStr('5');
        }
      }

      if ((y>=70) && (y<=120))  // Center row
      {
        if ((x>=10) && (x<=60))  // Button: 6
        {
          waitForIt(10, 70, 60, 120);
          updateStr('6');
        }
        if ((x>=70) && (x<=120))  // Button: 7
        {
          waitForIt(70, 70, 120, 120);
          updateStr('7');
        }
        if ((x>=130) && (x<=180))  // Button: 8
        {
          waitForIt(130, 70, 180, 120);
          updateStr('8');
        }
        if ((x>=190) && (x<=240))  // Button: 9
        {
          waitForIt(190, 70, 240, 120);
          updateStr('9');
        }
        if ((x>=250) && (x<=300))  // Button: 0
        {
          waitForIt(250, 70, 300, 120);
          updateStr('0');
        }
      }

      if ((y>=130) && (y<=180))  // Upper row
      {
        if ((x>=10) && (x<=150))  // Button: Clear
        {
          waitForIt(10, 130, 150, 180);
          stCurrent[0]='\0';
          stCurrentLen=0;
          myGLCD.setColor(0, 0, 0);
          myGLCD.fillRect(0, 224, 319, 239);
        }
        if ((x>=160) && (x<=300))  // Button: Enter
        {
          waitForIt(160, 130, 300, 180);
          if (stCurrentLen>0)
          {
            for (x=0; x<stCurrentLen+1; x++)
            {
              stLast[x]=stCurrent[x];
            }
            stCurrent[0]='\0';
            stCurrentLen=0;
            myGLCD.setColor(0, 0, 0);
            myGLCD.fillRect(0, 208, 319, 239);
            myGLCD.setColor(0, 255, 0);
            myGLCD.print(stLast, LEFT, 208);
          }
          else
          {
            myGLCD.setColor(255, 0, 0);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            delay(500);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            myGLCD.setColor(0, 255, 0);
          }
        }
      }
    }
  }
}

y este es el resultado

El Sketch usa 24.450 bytes (75%) del espacio de almacenamiento de programa. El máximo es 32.256 bytes.
Las variables Globales usan 217 bytes (10%) de la memoria dinámica, dejando 1.831 bytes para las variables locales. El máximo es 2.048 bytes.

Gracias amigo surbyte pero no me funciona.No es tan sencillo como copiar y pegar.Si fuera asi no existiria el foro me imagino jajaja.

EL tema que pude ver es que tiene que ver con el hardware y la libreria que uso.

Te lo voy a hacer mas facil asi se entiende mejor.Este pequeño codigo lo que hace son 3 botones rectangulares rojos en la parte superior derecha:

#include <SPI.h>


#include "Adafruit_GFX.h"     
#include "Adafruit_ILI9341.h" 
#include "URTouch.h"          

#define TFT_DC 9              
#define TFT_CS 10             
#define TFT_RST 8            
#define TFT_MISO 12           
#define TFT_MOSI 11           
#define TFT_CLK 13            


Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);  

#define t_SCK 3               
#define t_CS 4                
#define t_MOSI 5              
#define t_MISO 6              
#define t_IRQ 7               

URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);


void setup() {

 tft.begin();
tft.fillScreen(BLACK);

  tft.fillRoundRect (12,15,30,80,5,RED);//50,100,30,80,5,RED
  tft.fillRoundRect (50,15,30,80,5,RED);
  tft.fillRoundRect (88,15,30,80,5,RED);



   delay(500);

 
}

Y esta seria la parte que me falta entender :



void loop()
{

  int x, y;                          

  while(ts.dataAvailable())         

  {
    ts.read();                      
    x = ts.getX();     -----------> se que todo el chiste esta aca.             
    y = ts.getY();                  
    
  
}

Lo que necesito y es algo que me cuesta mucho encontrar es ,teniendo en cuenta este codigo,como detectar el boton presionado en el touch.Lo demas me arreglo solo.
Se que hay una tecnica que es detectar el area de presion para que cuando presiones en cualquier parte de ella ,el boton sea detectado correctamente.

BUeno ese es el problema que tengo.Espero haber sido claro y que me puedas dar una mano.

Un gran abrazo!

Hablamos de dos cosas distinas. Yo hablo de la librería y el ejemplo de la librería y vos hablas de un programa propio.
Me equivoco?
Ahh y usas librerías de Adafruit. bue.. otro tema, estoy que paso del inconveniente.
Yo uso UTFT y URTouch y vos usas
Adafruit_GFX, Adafruit_ILI9341 y URTouch

Dos escenarios diferentes.

No amigo, estoy tratando de organizar las toneladas de preguntas y conceptos que tengo desconocidos y ser lo mas prolijo que puedo en mis apreciaciones.

Para que quede definitivamente entendido es, que al dia de hoy, no se como hacer una rutina que detecte un boton presionado en la pantalla tactil.

He visto que hay una tecnica de leer el area o cantidad de pixeles que conforman el dibujo del boton pero no la entiendo y debo decir que ,el que lo sabe, no estaria siendo generoso en compartirlo.

Todo lo demas lo he resuelto solo pero me estanqué en ese punto.

Por ejemplo he visto esta porcion de otro codigo que es asi:

if (currentpage == 0)
  {
    if (p.z > 10 && p.z < 1000)
    {
    
 // aqui aparenteente pregunta por el area del dibujo  y si coincide es el boton de "FLAPPYBIRD" imprime serialmente la palabra "flappybird"pero no se como saco estos valores.
 
if (p.x > 736 && p.x < 855 && p.y > 255 && p.y < 725  && p.z > MINPRESSURE && p.zMAXPRESSURE)
    
  {
        Serial.println("FlappyBird");

        tft.fillRoundRect(60, 180, 200, 40, 8, WHITE);

        delay(70);

        tft.fillRoundRect(60, 180, 200, 40, 8, RED);
        tft.drawRoundRect(60, 180, 200, 40, 8, WHITE);
        tft.setCursor(65, 195);

        tft.println("   FlappyBird");
        delay(70);

        currentpage = 1;

        nextDrawLoopRunTime = millis() + DRAW_LOOP_INTERVAL;
        crashed = false;
        running = false;
        scrPress = false;

        startGame();
      }

      
//Aca hace lo mismo

else if (p.x > 563 && p.x < 683 && p.y > 275 && p.y < 750)
      {
        Serial.println("RGB-MIXER");

        tft.fillRoundRect(60, 130, 200, 40, 8, WHITE);   //rgb led
        delay(70);

        tft.fillRoundRect(60, 130, 200, 40, 8, RED);   //rgb led
        tft.drawRoundRect(60, 130, 200, 40, 8, WHITE);   //rgb led
        tft.setCursor(105, 145);

        tft.print("RGB-Mixer");
        delay(70);

        currentpage = 2;
        x = 0;
        y = 0;
        p.z = 0;
        redpos = BAR_MINY + 12;
        greenpos = BAR_MINY + 12;
        bluepos = BAR_MINY + 12;
        oldrpos = redpos;
        oldgpos = greenpos;
        oldbpos = bluepos;

        drawrgb();

En esta rutina que extraje lo que no me queda claro es como saco los vaores de p.x porque no me dan las cuentas.¿Seran la cantidad de pixeles del dibujo??

En fin, vos quizas te das cuenta.

Espero haber sido un poco mas claro.

Hola,
Mira Aquí . A ver si es lo que buscas.

Muchas gracias Rodri, si seria algo asi per ono pude hacerlo andar a tu codigo.
¿ como hago para cargar correctamente la libreria "boton.h" porque no se puede cargar por "cargar librerias .zip" del ARDUINO y estoy teniendo errores e tiempo de compilacion.

Mira aqui te coloco el header de mis programas que con esto me funcionan las dos aplicaciones demo que hice correr en base a mi conexionado:

#include <SPI.h>
#include "Adafruit_GFX.h"     
#include "Adafruit_ILI9341.h" 
#include "URTouch.h"          

#define TFT_DC 9              
#define TFT_CS 10             
#define TFT_RST 8             
#define TFT_MISO 12           
#define TFT_MOSI 11           
#define TFT_CLK 13            

#define BLACK   0x0000

//int BLUE = tft.color565(50, 50, 255);

#define DARKBLUE 0x0010
#define VIOLET 0x8888
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY   tft.color565(64, 64, 64);
#define GOLD 0xFEA0
#define BROWN 0xA145
#define SILVER 0xC618
#define LIME 0x07E0

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);  
#define FACECOLOR 0xFFFF
#define t_SCK 3               
#define t_CS 4                
#define t_MOSI 5              
#define t_MISO 6              
#define t_IRQ 7               
#define BACKCOLOR 0xFFFF 
#define LINECOLOR 0x0000  

URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ); 


void setup()}

{


void loop()}

{
------------------------------------------------------------------------------------------------------------------
Otra cosa que no entiendo son los valores que le pusiste a esta linea de codigo:

 ps.x = map(ps.x, 150, 900, tft.width(), 0); // Para rotación 0
  ps.y = map(ps.y, 110, 900, tft.height(), 0); // Para rotación 0

¿Como llegaste al "900"? .Mi modulo es el 240x320.

Un gran abrazo!

Acá tenes algo link que puede servirte perooo tenés que adaptarlo

Otra opcion link 2

Tienes que poner el archivo botón.h en la misma carpeta donde tengas el archivo.ino

No esta preparado como una librería de arduino, no era lo que pretendía, además no esta del todo terminada, es mas que nada para que cojas ideas.
Hay distintos tamaños de pantallas, la mía simplemente es mas grande.

Gracias amigazo por la atencion pero estos dos links que me pasas ya los probe tambien porque los tengo de "ejemplos" en el IDE de ARDUINO pero tienen la libreria de un controlador resistivo que es el STMPE610 controlador que es resistivo y mi modulo es capacitivo.

Yo tengo el TJCTM24028 SPI y tiene el controlador XPT2046.

SI le bloqueo esa libreria, me da errores porque esta escrito en funcion de ese controlador.

Yo necesito una rutinalo mas sencilla que se pueda escribir aunque ocupe lineas de codigo y que sea codigo APB (a prueba de brutos) que lea 3 botones ubicado en estas coordenadas:

tft.fillRoundRect (12,15,30,80,5,RED);
tft.fillRoundRect (50,15,30,80,5,RED);
tft.fillRoundRect (88,15,30,80,5,RED);

Vos tenes un conocimiento mucho mas acabado de la programacion y usas matrices y arreglos complejos para apuntar vectores y demas que yo no tengo experiencia.

Aqui te paso este codio que funciona perfecto asi como esta y es el que me permite hacer funcionar mi modulo:

Este codigo es el que tengo cargado en mi modulo a la espera de poder avanzar con la deteccion de la tecla.

#include <SPI.h>
#include "Adafruit_GFX.h"     
#include "Adafruit_ILI9341.h" 
#include "URTouch.h"          

#define TFT_DC 9              
#define TFT_CS 10             
#define TFT_RST 8             
#define TFT_MISO 12           
#define TFT_MOSI 11           
#define TFT_CLK 13            

#define BLACK   0x0000


#define DARKBLUE 0x0010
#define VIOLET 0x8888
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY   tft.color565(64, 64, 64);
#define GOLD 0xFEA0
#define BROWN 0xA145
#define SILVER 0xC618
#define LIME 0x07E0

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);  

#define FACECOLOR 0xFFFF
#define t_SCK 3               
#define t_CS 4                
#define t_MOSI 5              
#define t_MISO 6              
#define t_IRQ 7               
#define BACKCOLOR 0xFFFF // White
#define LINECOLOR 0x0000  //int opcion = 1

URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ); 

void setup() {

 tft.begin();
  
  tft.fillScreen(BLACK);
  tft.fillRoundRect (12,15,30,80,5,RED);//50,100,30,80,5,RED
  tft.fillRoundRect (50,15,30,80,5,RED);
  tft.fillRoundRect (88,15,30,80,5,RED);


//   delay(500);

 
}
  


void loop(){
 
}

Me parece que va a ser ms facil que trabajemos sobre este codigo que a mi me funciona que probar cientos de otros codigos.

Un abrazo grande y espero me puedas ayudar!

¿Entonces lo que quieres saber es si han pulsado el botón?

SI asi es, si lo pulsaron yo me voy a otra rutina.

Saludos

Ya resolvi el tema de los botones y del menu.

Gracias por tu confiable e idonea ayuda amigo.

CUalquier cosa te molesto nuevamente :slight_smile: :slight_smile:

Un gran abrazo y buen fin de semana

Gabriel

ganimides2017:
Ya resolvi el tema de los botones y del menu.

Gracias por tu confiable e idonea ayuda amigo.

CUalquier cosa te molesto nuevamente :slight_smile: :slight_smile:

Un gran abrazo y buen fin de semana

Gabriel

podrias postear la solucion ,puede ayudar a otra persona que llegue a este post con la misma duda.