Menu en pantalla TFT 3.5

Saludos Cesar Vasquez de Republica Dominicana Saluda a esta comunidad
me gustaria una ayuda para poder mejorar un codigo para un menu,este funciona bien pero me gustaria poder cambiar la parte donde estan los Setpoint,estos aumentan al pulsar el encoder,me gustaria que fuera girando la rueda,el programa esta cargado en un arduino mega y la pantalla es TFT 3,5 '' no touch



aqui el codigo

[code]
#include <Wire.h> 
#include <TFT_HX8357.h> // Hardware-specific library
#include <PID.h>
#include <encoder.h>
TFT_HX8357 tft = TFT_HX8357();       // Invoke custom library

int menu1_Value = 0;
int contador = 0; 
int A_estado_actual;
int A_ultimo_estado;

#define COUNT(x) sizeof(x)/sizeof(*x)  // Macro para contar el numero de elementos de un array
const byte SW   = 48; // 4 Pin encoder SW  ( Cable Naranja )
const byte DT   = 46; // 3 Pin encoder DT   ( Cable Amarillo )
const byte CLK  = 44; // 2 Pin encoder CLK ( Cable Verde  )
const byte rowsLCD    = 25; // Filas del LCD
const byte columnsLCD = 25; // Columnas del LCD

enum Button{ Unknown, Ok, Left, Right } btnPressed;     // Enumerador con los diferentes botones disponibles
enum Screen{ Menu1, Menu2,Menu3, Flag, Number,Bomba,FAN1,FAN2,Temp };              // Enumerador con los distintos tipos de submenus disponibles
//int maxLabelWidth = 0;

const char *txMENU[] = {          // Los textos del menu principal, la longitud maxima = columnsLCD-1, rellenar caracteres sobrantes con espacios.
    "Encender Bomba",
    "Encender FAN 1",
    "Encender FAN 2",
    "Mover Motores",
    "Ajustar Temperatura ",
    "Salir "
};

const byte iMENU = COUNT(txMENU);                       // Numero de items/opciones del menu principal
enum eSMENU1{ motor_X, motor_Y, motor_Z, motor_xy, motor_E,homexy,sale };  // Enumerador opciones del submenu 1 (tienen que seguir el mismo orden que los textos)
const char *txSMENU1[] = {                           // Textos del submenu 1, longitud maxima = columnsLCD-2, rellenar caracteres con espacios
    "MOTOR Eje X",
    "MOTOR Eje Y",
    "MOTOR Eje Z",
    "MOTOR Eje X/Y",
    "MOTOR E ",
    "HOME X / Y",
    "SALIR"
};

const char *txSMENU2[] = { // Los textos del menu principal, la longitud maxima = columnsLCD-1, rellenar caracteres  con espacios.
        "SetPoint Eje X :",
        "SetPoint Eje Y :",
        "SetPoint Eje Z :",
         "SetPoint Eje X/Y :",
        "SetPoint Eje E :",
       "SetPoint HOME X/Y :",
       "SALIR"
};
/* ESTRUCTURAS CONFIGURACION */
struct MYDATA{       // Estructura STRUCT con las variables que almacenaran los datos que se guardaran en la memoria EEPROM
        int show;
    };
union MEMORY{      // Estructura UNION para facilitar la lectura y escritura en la EEPROM de la estructura STRUCT
    MYDATA d;
    byte b[sizeof(MYDATA)];
}
memory;
void drawArrow(int arrowX, int arrowY, int arrowSize, unsigned int color) {
  // Dibujar el cuerpo de la flecha (un rectángulo)
      tft.fillRect(arrowX + arrowSize, arrowY - 2, 20, 8, color);
  // Dibujar la punta de la flecha (un triángulo)
      tft.fillTriangle(arrowX, arrowY, arrowX + arrowSize, arrowY + arrowSize / 2, arrowX + arrowSize, arrowY - arrowSize / 2, color);
}

void setup()
{
      pinMode(SW,  INPUT_PULLUP);
      pinMode(DT,  INPUT_PULLUP);
      pinMode(CLK, INPUT_PULLUP);
        tft.init();
        tft.setRotation(1);
        tft.setTextFont(1);
        tft.setTextSize(2.5);
   }

void loop()
{
    static unsigned long tNow      = 0;
    static unsigned long tPrevious = 0;

    tNow = millis();
    btnPressed = readButtons();
      openMenu(); 
       }
 //  MUESTRA EL MENU PRINCIPAL EN EL LCD.
/****************** Menu *************************************************************/
void openMenu()
{
    byte Menu       = 0;
    boolean exitMenu   = false;
    boolean forcePrint = true;

      tft.fillScreen(TFT_BLACK); 
      tft.setTextColor(TFT_GREEN,TFT_BLACK);
      tft.setTextFont(1);
      tft.setTextSize(3.5);
      tft.setCursor(170,0); tft.print(" Menu  ");
      tft.setTextColor(TFT_ORANGE);
      tft.setTextSize(3);
      tft.setCursor(100,25); tft.print("Control Manual  ");
      tft.setTextSize(2.5);
   
    int arrowX = 270 ;
    int arrowY = 65 ;
    int arrowSize = 20;
    drawArrow(arrowX, arrowY, arrowSize, TFT_RED);
    
    while( !exitMenu )
        {
        btnPressed = readButtons();

        if( btnPressed == Button::Left && Menu-1 >= 0 )
        {
            Menu--;
       
      tft.setTextColor(TFT_GREEN,TFT_BLACK);
      tft.setTextFont(1);
      tft.setTextSize(3.5);
      tft.setCursor(170,0); tft.print(" Menu  ");
      tft.setTextColor(TFT_ORANGE);
      tft.setTextSize(3);
      tft.setCursor(100,25); tft.print("Control Manual  ");
    int arrowX = 270 ;
    int arrowY = 55 +10+ 25 *Menu ;
    int arrowSize = 20;
      drawArrow(arrowX, arrowY, arrowSize, TFT_RED);
      drawArrow(arrowX, arrowY+25, arrowSize, TFT_BLACK);
        }
        else if( btnPressed == Button::Right && Menu+1 < iMENU )
        {
            Menu++;
         tft.setTextColor(TFT_GREEN);
      tft.setTextFont(1);
      tft.setTextSize(3.5);
      tft.setCursor(170,0); tft.print(" Menu  ");
      tft.setTextColor(TFT_ORANGE);
      tft.setTextSize(3);
      tft.setCursor(100,25); tft.print("Control Manual  ");
      tft.setTextSize(2.5);
    int arrowX = 270 ;
    int arrowY = 55 +10+ 25 *Menu ;
    int arrowSize = 20;
        drawArrow(arrowX, arrowY-25, arrowSize, TFT_BLACK);
        drawArrow(arrowX, arrowY, arrowSize, TFT_RED);
    
        }
        else if( btnPressed == Button::Ok )
       
        {
            switch( Menu )
                  {           
                case 0: openSubMenu( Menu, Screen::Bomba,   &memory.d.show, 0, 1); break;
                case 1: openSubMenu( Menu, Screen::FAN1,  &memory.d.show, 0, 1); break;
                case 2: openSubMenu( Menu, Screen::FAN2,  &memory.d.show, 0, 1); break;
                case 3: openSubMenu( Menu, Screen::Menu1,  &memory.d.show, 0, COUNT(txSMENU1)-1 ); break;
                case 4:openSubMenu( Menu, Screen::Temp,   &memory.d.show, 0, 1  ); break;
                case 5: exitMenu = true; break; //Salir t
                
                  }
     
            forcePrint = true;
              }
            if( !exitMenu && (forcePrint || btnPressed != Button::Unknown) )
                {
            forcePrint = false;
            static const byte endFor1 = (iMENU+rowsLCD-1)/rowsLCD;
            int graphMenu     = 0;
            
            for( int i=1 ; i<=endFor1 ; i++ )
                {
                if( Menu < i*rowsLCD )
                    {
                    graphMenu = (i-1) * rowsLCD;
                    break;
                    }
                }

            byte endFor2 = graphMenu+rowsLCD;

for (int i = 0; i < 6; i++) {
    tft.setCursor(20, 50 +10+ 25 * i);
    if (i == Menu) {   
      tft.setTextColor(TFT_RED,TFT_BLACK);  

        
    } else {      
      tft.setTextColor(TFT_CYAN,TFT_BLACK);
    }
      tft.setTextSize(2);   
      tft.println(txMENU[i] );
     
          }
        }
      }
    }
/****************** Fin Menu *************************************************************/

/******************  SubMenu *************************************************************/

void openSubMenu( byte menuID, Screen screen, int *value, int minValue, int maxValue )
{
    boolean exitSubMenu = false;
    boolean forcePrint  = true;
    byte idxMenu       = 0;
    while( !exitSubMenu )
        {
        btnPressed = readButtons();

         if( btnPressed == Button::Left && (*value)-1 >= minValue )
            {
            (*value)--;
            }
        else if( btnPressed == Button::Right && (*value)+1 <= maxValue )
            {
            (*value)++;
            }
          
        if( !exitSubMenu && (forcePrint || btnPressed != Button::Unknown) )
        {
            forcePrint = false;
              tft.fillScreen(TFT_BLACK); 
              tft.setTextColor(TFT_GREEN);
              tft.setTextFont(1);
              tft.setTextSize(3.5);
              tft.setCursor(170,0); tft.print(" Menu  ");
              tft.setTextColor(TFT_ORANGE);
              tft.setCursor(100,25); tft.print("Control Manual  ");           
              tft.setTextColor(TFT_CYAN);
              tft.setTextSize(2.5);
              tft.setCursor(170,61);
              tft.print(txMENU[menuID]);

            if( screen == Screen::Menu1 )
            {
                tft.setTextColor(TFT_YELLOW);
              
  for (int i = 0; i < 7; i++) {
              tft.setCursor(20, 105+ 25 * i);
    if (i == *value) {   
                tft.setTextColor(TFT_RED,TFT_BLACK);  
        int arrowX = 190 ;
        int arrowY = 110+ 25 *i ;
        int arrowSize = 20;
        drawArrow(arrowX, arrowY-25, arrowSize, TFT_BLACK);
        drawArrow(arrowX, arrowY, arrowSize, TFT_RED);  
    } 
    else 
    {      
                  tft.setTextColor(TFT_CYAN,TFT_BLACK);
    }
                  tft.setTextSize(2);   
                  tft.println(txSMENU1[i] );
        }
          }            
            else if( screen == Screen::Bomba )
            {
                tft.setTextColor(TFT_YELLOW);
                tft.setCursor(325+columnsLCD/2-1, 61);
        
            if( btnPressed == Button::Ok )
            {
             exitSubMenu = true;
            }  
            }
            
            else if( screen == Screen::FAN1 )
            {
                tft.setTextColor(TFT_YELLOW);
                tft.setCursor(325+columnsLCD/2-1, 61);
                tft.print(*value == 0 ? "NO" : "SI");
           
            if( btnPressed == Button::Ok )
            {
             exitSubMenu = true;
            }   
            }

            else if( screen == Screen::FAN2 )
            {
              tft.setTextColor(TFT_YELLOW);
                tft.setCursor(325+columnsLCD/2-1, 61);
                tft.print(*value == 0 ? "NO" : "SI");
            
            if( btnPressed == Button::Ok )
            {
             exitSubMenu = true;
            }    
            }

            else if( screen == Screen::Temp )
            {
              tft.setTextColor(TFT_YELLOW);
                tft.setCursor(325+columnsLCD/2-1, 61);
            
            if( btnPressed == Button::Ok )
            {
             exitSubMenu = true;
             
            }     
            }
/******************Item SubMenu *************************************************************/
 
        if( btnPressed == Button::Ok )
        {
          
             tft.setTextColor(TFT_CYAN);
           
          for (int i = 0; i < 7; i++)
          {
    tft.setCursor(20, 50 +10+ 25 * i);
   
      if (i == Screen::Menu2)
        {   
    if (txSMENU2[*value] == "SALIR")
        {   
         exitSubMenu = true;  
        }
        
      if(menu1_Value < 10) //we do not go above 100
      {
        menu1_Value++; 
         tft.setTextColor(TFT_YELLOW);
         tft.setCursor(200,85);
                 tft.print(txSMENU2[*value]); 
         tft.setCursor(395, 85);
         tft.print(menu1_Value); 
         
      }
      else
      {
        menu1_Value = 0;  
      }      
       }
     }            
    }
    /****************** Fin Item SubMenu *************************************************************/            
   }/****************** exit SubMenu *******/
  }/****************** while *******/

        tft.fillScreen(TFT_BLACK); 
        tft.setTextColor(TFT_GREEN);
        tft.setTextFont(1);
        tft.setTextSize(3.5);
        tft.setCursor(170,0); tft.print(" Menu  ");
        tft.setTextColor(TFT_ORANGE);
        tft.setTextSize(3);
        tft.setCursor(100,25); tft.print("Control Manual  ");
        tft.setTextSize(2.5);
         openMenu(); 
         int arrowX = 270 ;
      int arrowY = 65 ;
      int arrowSize = 20;
    drawArrow(arrowX, arrowY, arrowSize, TFT_RED);       
}

/****************** Fin SubMenu *************************************************************/

void readConfiguration()
{       
        memory.d.show   = 1;        
}

Button readButtons()
{
    static boolean oldA = HIGH;
    static boolean newA = LOW;
    static boolean newB = LOW;

    btnPressed = Button::Unknown;
    newA = digitalRead(DT);
    newB = digitalRead(CLK);

    if( !oldA && newA )
    {
        btnPressed = !newB ? Button::Left : Button::Right;
        delay(50);
    }
    else if( !digitalRead(SW) )
    {
        while(!digitalRead(SW));
        btnPressed = Button::Ok;
        delay(50);
    }

    oldA = newA;
    return btnPressed;
}
[/code]

He trasladado su tema de una categoría de idioma inglés del foro a la categoría International > Español @cesar6174.

En adelante por favor usar la categoría apropiada a la lengua en que queráis publicar. Esto es importante para el uso responsable del foro, y esta explicado aquí la guía "How to get the best out of this forum".
Este guía contiene mucha información útil. Por favor leer.

De antemano, muchas gracias por cooperar.

Gracias por el aviso,lamentablemente soy un nuevo suscriptor que entre hoy y no estoy familiarizado con este foro,mil disculpas

1 Like

Moderador:
Por favor, lee las Normas del foro
Si posteas en el foro en inglés usa idioma inglés para expresarte, eso incluye los comentarios de tu código. Si un código tiene comentarios en español también moverán tu hilo a esta sección en Español.
Si escribes en español debes usar el foro Arduino en español