https://www.youtube.com/watch?v=Ui2EiJ4cEg8

Hello good people out there..

First thing first .. thank you for the asume and helpsome comunity .. though i havent realy used it before and this be the first time i love it is intelegents and healtyness :smiley: i have very limited knowledge about programming in general so i kind of need help with even the basics ..
and by the way sorry for my spelling mistakes..

I am her seeking help with a very simple arduino projet, making 6 relays work with arduino touch interface,
3 of them individually and
3 of them where they chacel eachother..

I have modified a sketch come across online among the 100 others i have tried it and it seems like it has good potentials even for a nobi like me :-S .. and talking about the skech thanks upfront to the orginal creater of the sketch and all other pople involved in the libarys and more..

I am using a touchscreen that seems to be mirrored in the touch functions or something .. so it makes things even more complicated for a greeny me !"

I will appreciate if somone could help me with either this or similar button interface, that actuely works with my shield..

I have a made a video showing how the interface and how it reacts now.. and her is the code

//Programa : Teste Display Touch Arduino - Touchscreen
//Autor : FILIPEFLOP
  
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
  
#define YP A1 // Y+ is on Analog1 (use A3 para o 9341)
#define XM A2 // X- is on Analog2 (use A2 para o 9341)
#define YM 7 // Y- is on Digital7 (use 9 para o 9341)
#define XP 6 // X+ is on Digital6 (use 8 para o 9341)
  
#define TS_MINX 40  // Use 150 para o 9341
#define TS_MINY 100 // Use 120 para o 9341
#define TS_MAXX 780
#define TS_MAXY 135
  
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);
 
//Definicao de cores
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF
  
//PP_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
  
// Armazena o estado dos botões
bool valor_botao1 = 0;
bool valor_botao2 = 0;
bool valor_botao3 = 0;
bool valor_botao4 = 0;
bool valor_botao5 = 0;

  
#define MINPRESSURE 5
#define MAXPRESSURE 1000
  
void setup(void) 
{
  Serial.begin(9600);
  Serial.println("TFT Test");
  //identifier == 0x9325;
  tft.reset();
  delay(500);
  //uint16_t identifier = tft.readID(0x0);
  //Serial.print("Driver encontrado: ");
  //Serial.println(identifier, HEX);
  
 tft.begin(0x9341); //Use esta linha para o controlador 9341
 //tft.begin(0x9325);
  //tft.initDisplay();
  tft.fillScreen(BLACK);
  tft.setRotation(2);
  
  // Inicio - Texto e botoes
 
  //button 1
  
  tft.drawRoundRect(75, 25, 160, 50, 50, WHITE);           //big box
  tft.drawRoundRect(5, 25, 62, 50, 50, WHITE);             // smal box
  tft.setTextColor(YELLOW);                                //Color
  tft.setTextSize(2);                                      //text size
  tft.setCursor(135, 42);                                  //Box number position
  tft.println("1");                                        //Box Number
  
  //Button 2
 
  tft.drawRoundRect(75, 85, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 85, 62, 50, 50, WHITE);
  tft.setTextColor(GREEN);
  tft.setTextSize(2);
  tft.setCursor(135, 102);
  tft.println("2");
 
  //Button 3
  
  tft.drawRoundRect(75, 145, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 145, 62, 50, 50, WHITE);
  tft.setTextColor(BLUE);
  tft.setTextSize(2);
  tft.setCursor(135, 162);
  tft.println("3");
  
  //Button 4
  
  tft.drawRoundRect(75, 205, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 205, 62, 50, 50, WHITE);
  tft.setTextColor(RED);
  tft.setTextSize(2);
  tft.setCursor(135, 222);
  tft.println("4");
  
  //Button 5
  
  tft.drawRoundRect(75, 265, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 265, 62, 50, 50, WHITE);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.setCursor(135, 282);
  tft.println("5");
  
  //Preenchimento OFF -OFF Buttons text positioning 
  tft.setTextColor(WHITE);
  tft.setCursor(20, 44);
  tft.println("OFF");
  tft.setCursor(20, 104);
  tft.println("OFF");
  tft.setCursor(20, 164);
  tft.println("OFF");
  tft.setCursor(20, 224);
  tft.println("OFF");
  tft.setCursor(20, 284);
  tft.println("OFF");
}
  
void loop()
{
  TSPoint p = ts.getPoint();
  pinMode(XM, OUTPUT);
  digitalWrite(XM, LOW);
  pinMode(YP, OUTPUT);
  digitalWrite(YP, HIGH);
  pinMode(YM, OUTPUT);
  digitalWrite(YM, LOW);
  pinMode(XP, OUTPUT);
  digitalWrite(XP, HIGH);
  
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
    p.x = tft.width() - (map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
    if (p.y > 200)
    {
      Serial.print("py: ");
      Serial.print(p.y);
      Serial.print(" px: ");
      Serial.print(p.x);
  
     //B1 
     if (p.x > 235 & p.x < 295)
      {
        if (valor_botao1 == 0)
        {
          tft.fillRoundRect(5, 25, 62, 50, 50, YELLOW);
          mostra_on(20, 44);
          valor_botao1 = !valor_botao1;
        }
        else
        {
          tft.fillRoundRect(5, 25, 62, 50, 50, BLACK);
          mostra_off(20, 44);
          valor_botao1 = !valor_botao1;
        }
      } 
      //B2
      if (p.x > 235 & p.x < 295)
      {
        if (valor_botao1 == 0)
        {
          tft.fillRoundRect(5, 85, 62, 50, 50, GREEN);
          mostra_on(20, 104);
          valor_botao2 = !valor_botao2;
        }
        else
        {
          tft.fillRoundRect(5, 85, 62, 50, 50, BLACK);
          mostra_off(20, 104);
          valor_botao2 = !valor_botao2;
        }
      }
      //B3
      if (p.x > 235 & p.x < 295)
      {
        if (valor_botao2 == 0)
        {
          tft.fillRoundRect(5, 145, 62, 50, 50, BLUE);
          mostra_on(20, 164);
          valor_botao3 = !valor_botao3;
        }
        else
        {
          tft.fillRoundRect(5, 145, 62, 50, 50,  BLACK);
          mostra_off(20, 164);
          valor_botao3 = !valor_botao3;
        }
      }
      //B4
      if (p.x > 126 & p.x < 184)
      {
        if (valor_botao3 == 0)
        {
          tft.fillRoundRect(5, 205, 62, 50, 50, RED);
          mostra_on(20, 224);
          valor_botao4 = !valor_botao4;
        }
        else
        {
          tft.fillRoundRect(5, 205, 62, 50, 50,  BLACK);
          mostra_off(20, 224);
          valor_botao4 = !valor_botao4;
        }
      }
      //B5
      if (p.x > 10 & p.x < 58)
      {
        if (valor_botao4 == 0)
        {
          tft.fillRoundRect(5, 265, 62, 50, 50, CYAN);
          mostra_on(20,284);
          valor_botao5 = !valor_botao5;
        }
        else
        {
          tft.fillRoundRect(5, 265, 62, 50, 50,  BLACK);
          mostra_off(20,284);
          valor_botao5 = !valor_botao5;
        }
      }
    }
  }
}
  
void mostra_on(int y, int x)
{
  tft.setTextColor(WHITE);
  tft.setCursor(y, x);
  tft.println("ON");
  delay(100);
}
  
void mostra_off(int y, int x)
{
  tft.setTextColor(WHITE);
  tft.setCursor(y, x);
  tft.println("OFF");
  delay(100);
}

will appreciate any help.

!!!! her is the video (20220513 205208 - YouTube)

This (below) chunk of your code seems to mix the "Bx" with "valor_botaoX"... I would expect B2 to have valor_botao2 in the "if" statement but I see under B2, "botao1" ... and this occurs in B3 through B5.

I suspect "copy/paste" occured, but correcting the button numbers did not.

     //B1
      if (p.x > 235 & p.x < 295)
      {
        if (valor_botao1 == 0)
        {
          tft.fillRoundRect(5, 25, 62, 50, 50, YELLOW);
          mostra_on(20, 44);
          valor_botao1 = !valor_botao1;
        }
        else
        {
          tft.fillRoundRect(5, 25, 62, 50, 50, BLACK);
          mostra_off(20, 44);
          valor_botao1 = !valor_botao1;
        }
      }
      //B2
      if (p.x > 235 & p.x < 295)
      {
        if (valor_botao1 == 0)
        {
          tft.fillRoundRect(5, 85, 62, 50, 50, GREEN);
          mostra_on(20, 104);
          valor_botao2 = !valor_botao2;
        }
        else
        {
          tft.fillRoundRect(5, 85, 62, 50, 50, BLACK);
          mostra_off(20, 104);
          valor_botao2 = !valor_botao2;
        }
      }
      //B3
      if (p.x > 235 & p.x < 295)
      {
        if (valor_botao2 == 0)
        {
          tft.fillRoundRect(5, 145, 62, 50, 50, BLUE);
          mostra_on(20, 164);
          valor_botao3 = !valor_botao3;
        }
        else
        {
          tft.fillRoundRect(5, 145, 62, 50, 50,  BLACK);
          mostra_off(20, 164);
          valor_botao3 = !valor_botao3;
        }
      }
      //B4
      if (p.x > 126 & p.x < 184)
      {
        if (valor_botao3 == 0)
        {
          tft.fillRoundRect(5, 205, 62, 50, 50, RED);
          mostra_on(20, 224);
          valor_botao4 = !valor_botao4;
        }
        else
        {
          tft.fillRoundRect(5, 205, 62, 50, 50,  BLACK);
          mostra_off(20, 224);
          valor_botao4 = !valor_botao4;
        }
      }
      //B5
      if (p.x > 10 & p.x < 58)
      {
        if (valor_botao4 == 0)
        {
          tft.fillRoundRect(5, 265, 62, 50, 50, CYAN);
          mostra_on(20, 284);
          valor_botao5 = !valor_botao5;
        }
        else
        {
          tft.fillRoundRect(5, 265, 62, 50, 50,  BLACK);
          mostra_off(20, 284);
          valor_botao5 = !valor_botao5;
        }
1 Like

Thank you for the your effort xfpd .. yes i did correct the button problems and also corrected the mapping that solved all the the problems so everything works as they should at this stage,, the only quideing i now need is how to add a code that makes 3 of the buttons cancel eachother, and so when one of the buttons is on ON stage the other 2 are OFF ..and all to controle the 5 relays of mine!

I have som relays lying around that i was thinking to use ,, and another thingperhaps most importend thing is do i need a Mega to pin everything to ore can it function with a few pins that are left on the Uno!!

Again appreciate your note..

and her is the corrected version of the code

//Programa : Teste Display Touch Arduino - Touchscreen
//Autor : FILIPEFLOP
  
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
  
#define YP A1 // Y+ is on Analog1 (use A3 para o 9341)
#define XM A2 // X- is on Analog2 (use A2 para o 9341)
#define YM 7 // Y- is on Digital7 (use 9 para o 9341)
#define XP 6 // X+ is on Digital6 (use 8 para o 9341)
  
#define TS_MINX 60  // Use 150 para o 9341
#define TS_MINY 100 // Use 120 para o 9341
#define TS_MAXX 780
#define TS_MAXY 135
  
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);
 
//Definicao de cores
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF
  
//PP_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
  
// Armazena o estado dos botões
bool valor_botao1 = 0;
bool valor_botao2 = 0;
bool valor_botao3 = 0;
bool valor_botao4 = 0;
bool valor_botao5 = 0;

  
#define MINPRESSURE 5
#define MAXPRESSURE 1000
  
void setup(void) 
{
  Serial.begin(9600);
  Serial.println("TFT Test");
  //identifier == 0x9325;
  tft.reset();
  delay(500);
  //uint16_t identifier = tft.readID(0x0);
  //Serial.print("Driver encontrado: ");
  //Serial.println(identifier, HEX);
  
 tft.begin(0x9341); //Use esta linha para o controlador 9341
 //tft.begin(0x9325);
  //tft.initDisplay();
  tft.fillScreen(BLACK);
  tft.setRotation(2);
  
  // Inicio - Texto e botoes
 
  //Button 1
  
  tft.drawRoundRect(75, 25, 160, 50, 50, WHITE);           //big box
  tft.drawRoundRect(5, 25, 62, 50, 50, WHITE);             // smal box
  tft.setTextColor(YELLOW);                                //Color
  tft.setTextSize(2);                                      //text size
  tft.setCursor(135, 42);                                  //Box number position
  tft.println("1");                                        //Box Number
  
  //Button 2
 
  tft.drawRoundRect(75, 85, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 85, 62, 50, 50, WHITE);
  tft.setTextColor(GREEN);
  tft.setTextSize(2);
  tft.setCursor(135, 102);
  tft.println("2");
 
  //Button 3
  
  tft.drawRoundRect(75, 145, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 145, 62, 50, 50, WHITE);
  tft.setTextColor(BLUE);
  tft.setTextSize(2);
  tft.setCursor(135, 162);
  tft.println("3");
  
  //Button 4
  
  tft.drawRoundRect(75, 205, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 205, 62, 50, 50, WHITE);
  tft.setTextColor(RED);
  tft.setTextSize(2);
  tft.setCursor(135, 222);
  tft.println("4");
  
  //Button 5
  
  tft.drawRoundRect(75, 265, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 265, 62, 50, 50, WHITE);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.setCursor(135, 282);
  tft.println("5");
  
  //Preenchimento OFF -OFF Buttons text positioning 
  tft.setTextColor(WHITE);
  tft.setCursor(20, 44);
  tft.println("OFF");
  tft.setCursor(20, 104);
  tft.println("OFF");
  tft.setCursor(20, 164);
  tft.println("OFF");
  tft.setCursor(20, 224);
  tft.println("OFF");
  tft.setCursor(20, 284);
  tft.println("OFF");
}
  
void loop()
{
  TSPoint p = ts.getPoint();
  pinMode(XM, OUTPUT);
  digitalWrite(XM, LOW);
  pinMode(YP, OUTPUT);
  digitalWrite(YP, HIGH);
  pinMode(YM, OUTPUT);
  digitalWrite(YM, LOW);
  pinMode(XP, OUTPUT);
  digitalWrite(XP, HIGH);
  
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
    p.x = tft.width() - (map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
    if (p.y > 200)
    {
      Serial.print("py: ");
      Serial.print(p.y);
      Serial.print(" px: ");
      Serial.print(p.x);
  
     //B1 
     if (p.x > 235 & p.x < 295)
      {
        if (valor_botao1 == 0)
        {
          tft.fillRoundRect(5, 25, 62, 50, 50, YELLOW);
          mostra_on(20, 44);
          valor_botao1 = !valor_botao1;
        }
        else
        {
          tft.fillRoundRect(5, 25, 62, 50, 50, BLACK);
          mostra_off(20, 44);
          valor_botao1 = !valor_botao1;
        }
      } 
      //B2
      if (p.x > 208 & p.x < 228)
      {
        if (valor_botao2 == 0)
        {
          tft.fillRoundRect(5, 85, 62, 50, 50, GREEN);
          mostra_on(20, 104);
          valor_botao2 = !valor_botao2;
        }
        else
        {
          tft.fillRoundRect(5, 85, 62, 50, 50, BLACK);
          mostra_off(20, 104);
          valor_botao2 = !valor_botao2;
        }
      }
      //B3
      if (p.x > 148 & p.x < 175)
      {
        if (valor_botao3 == 0)
        {
          tft.fillRoundRect(5, 145, 62, 50, 50, BLUE);
          mostra_on(20, 164);
          valor_botao3 = !valor_botao3;
        }
        else
        {
          tft.fillRoundRect(5, 145, 62, 50, 50,  BLACK);
          mostra_off(20, 164);
          valor_botao3 = !valor_botao3;
        }
      }
      //B4
      if (p.x > 109 & p.x < 129)
      {
        if (valor_botao4 == 0)
        {
          tft.fillRoundRect(5, 205, 62, 50, 50, RED);
          mostra_on(20, 224);
          valor_botao4 = !valor_botao4;
        }
        else
        {
          tft.fillRoundRect(5, 205, 62, 50, 50,  BLACK);
          mostra_off(20, 224);
          valor_botao4 = !valor_botao4;
        }
      }
      //B5
      if (p.x > 64 & p.x < 86)
      {
        if (valor_botao5 == 0)
        {
          tft.fillRoundRect(5, 265, 62, 50, 50, CYAN);
          mostra_on(20,284);
          valor_botao5 = !valor_botao5;
        }
        else
        {
          tft.fillRoundRect(5, 265, 62, 50, 50,  BLACK);
          mostra_off(20,284);
          valor_botao5 = !valor_botao5;
        }
      }
    }
  }
}
  
void mostra_on(int x, int y)
{
  tft.setTextColor(WHITE);
  tft.setCursor(x, y);
  tft.println("ON");
  delay(100);
}
  
void mostra_off(int x, int y)
{
  tft.setTextColor(WHITE);
  tft.setCursor(x, y);
  tft.println("OFF");
  delay(100);
}

...code that makes 3 of the buttons cancel each other, and so when one of the buttons is on ON stage the other 2 are OFF and all to controle the 5 relays...

Your question says "make 3 buttons cancel each other" but you have five buttons; B1 through B5... you can decide which buttons you want from this...

Start by making a new function; void botaoCambio() to receive each button color or black:


void botaoCambio (unsigned int colorB1, unsigned int colorB2, unsigned int colorB3, unsigned int colorB4, unsigned int colorB5)
{
  tft.fillRoundRect(5,  25, 62, 50, 50, colorB1);
  tft.fillRoundRect(5,  85, 62, 50, 50, colorB2);
  tft.fillRoundRect(5, 145, 62, 50, 50, colorB3);
  tft.fillRoundRect(5, 205, 62, 50, 50, colorB4);
  tft.fillRoundRect(5, 265, 62, 50, 50, colorB5);
}

Next, in each //Bx conditional ("IF") statement, color one button, and make the rest black:

//B1
if (valor_botao1 == 0)
{
  botaoCambio (YELLOW, BLACK, BLACK, BLACK, BLACK);
  mostra_on(20, 44);
  valor_botao1 = !valor_botao1;
}

// I am not certain you need the `else{}` to turn the button black after calling botaoCambio().

else
{
  tft.fillRoundRect(5, 25, 62, 50, 50, BLACK);
  mostra_off(20, 44);
  valor_botao1 = !valor_botao1;
}

//B2
if (p.x > 208 & p.x < 228)
{
  if (valor_botao2 == 0)
  {
    botaoCambio (BLACK, GREEN, BLACK, BLACK, BLACK);
    mostra_on(20, 104);
    valor_botao2 = !valor_botao2;
  }

  // I am not certain you need the `else{}` to turn the button black after calling botaoCambio().

  else
  {
    tft.fillRoundRect(5, 85, 62, 50, 50, BLACK);
    mostra_off(20, 104);
    valor_botao2 = !valor_botao2;
  }
}

Repeat the same code as above with the buttons you need.

This method is not "clean" because there is too much redundant code (for example, you do not need to make a BLACK button BLACK), but it demonstrates calling a multi-use function from different locations in the code.

1 Like

Thank you so much for the code you have made..:pray: looking forward to try it out when i get back home.

I need a more thorough method to control, manipulate the different buttons and the state they are in .....this codeline only changes the order of the colors and UI layout witch they are useing and there by not the stat they are in ..cuz this way only limits whether they are lighten with in the visual UI or not.. it is not realy detecting the stat they are in or changeing that in order to again change the stat of the one that has to go low or high simultaneously .. (i hope what i just wrote make sense :slight_smile:

So i need to isolate the corrent stat of each button in order to be able to manipulate the state of it as desire..

But ofc. your code adds more controle to the UI so thank you for that ..her is the code with the line you wated me to experiment on :slight_smile:

//Programa : Teste Display Touch Arduino - Touchscreen
//Autor : FILIPEFLOP
  
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
  
#define YP A1 // Y+ is on Analog1 (use A3 para o 9341)
#define XM A2 // X- is on Analog2 (use A2 para o 9341)
#define YM 7 // Y- is on Digital7 (use 9 para o 9341)
#define XP 6 // X+ is on Digital6 (use 8 para o 9341)
  
#define TS_MINX 60  // Use 150 para o 9341
#define TS_MINY 100 // Use 120 para o 9341
#define TS_MAXX 780
#define TS_MAXY 135
  
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);
 
//Definicao de cores
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF
  
//PP_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
  
// Armazena o estado dos botões
bool valor_botao1 = 0;
bool valor_botao2 = 0;
bool valor_botao3 = 0;
bool valor_botao4 = 0;
bool valor_botao5 = 0;

  
#define MINPRESSURE 5
#define MAXPRESSURE 1000

void botaoCambio (unsigned int colorB1, unsigned int colorB2, unsigned int colorB3, unsigned int colorB4, unsigned int colorB5)
{
  tft.fillRoundRect(5,  25, 62, 50, 50, colorB1);
  tft.fillRoundRect(5,  85, 62, 50, 50, colorB2);
  tft.fillRoundRect(5, 145, 62, 50, 50, colorB3);
  tft.fillRoundRect(5, 205, 62, 50, 50, colorB4);
  tft.fillRoundRect(5, 265, 62, 50, 50, colorB5);
}

void setup(void) 
{
  Serial.begin(9600);
  Serial.println("TFT Test");
  //identifier == 0x9325;
  tft.reset();
  delay(500);
  //uint16_t identifier = tft.readID(0x0);
  //Serial.print("Driver encontrado: ");
  //Serial.println(identifier, HEX);
  
 tft.begin(0x9341); //Use esta linha para o controlador 9341
 //tft.begin(0x9325);
  //tft.initDisplay();
  tft.fillScreen(BLACK);
  tft.setRotation(2);
  
  // Inicio - Texto e botoes
 
  //Button 1
  
  tft.drawRoundRect(75, 25, 160, 50, 50, WHITE);           //big box
  tft.drawRoundRect(5, 25, 62, 50, 50, WHITE);             //smal box
  tft.setTextColor(YELLOW);                                //Color
  tft.setTextSize(2);                                      //text size
  tft.setCursor(135, 42);                                  //Box number position
  tft.println("1");                                        //Box Number
  
  //Button 2
 
  tft.drawRoundRect(75, 85, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 85, 62, 50, 50, WHITE);
  tft.setTextColor(GREEN);
  tft.setTextSize(2);
  tft.setCursor(135, 102);
  tft.println("2");
 
  //Button 3
  
  tft.drawRoundRect(75, 145, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 145, 62, 50, 50, WHITE);
  tft.setTextColor(BLUE);
  tft.setTextSize(2);
  tft.setCursor(135, 162);
  tft.println("3");
  
  //Button 4
  
  tft.drawRoundRect(75, 205, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 205, 62, 50, 50, WHITE);
  tft.setTextColor(RED);
  tft.setTextSize(2);
  tft.setCursor(122, 222);
  tft.println("LIGHT");
  
  //Button 5
  
  tft.drawRoundRect(75, 265, 160, 50, 50, WHITE);
  tft.drawRoundRect(5, 265, 62, 50, 50, WHITE);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.setCursor(135, 282);
  tft.println("5");
  
  //Preenchimento OFF -OFF Buttons text positioning 
  tft.setTextColor(WHITE);
  tft.setCursor(20, 44);
  tft.println("OFF");
  tft.setCursor(20, 104);
  tft.println("OFF");
  tft.setCursor(20, 164);
  tft.println("OFF");
  tft.setCursor(20, 224);
  tft.println("OFF");
  tft.setCursor(20, 284);
  tft.println("OFF");
}
  
void loop()

{
  TSPoint p = ts.getPoint();
  pinMode(XM, OUTPUT);
  digitalWrite(XM, LOW);
  pinMode(YP, OUTPUT);
  digitalWrite(YP, HIGH);
  pinMode(YM, OUTPUT);
  digitalWrite(YM, LOW);
  pinMode(XP, OUTPUT);
  digitalWrite(XP, HIGH);
  
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
    p.x = tft.width() - (map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
    if (p.y > 200)
    {
      Serial.print("py: ");
      Serial.print(p.y);
      Serial.print(" px: ");
      Serial.print(p.x);
  
     //B1 
     if (p.x > 235 & p.x < 295)
      {
        if (valor_botao1 == 0)
        {
          
          tft.fillRoundRect(5, 25, 62, 50, 50, YELLOW);
          mostra_on(20, 44);
          valor_botao1 = !valor_botao1;
          botaoCambio (YELLOW, BLACK, BLACK, RED, CYAN);
        }
        else
        {
          tft.fillRoundRect(5, 25, 62, 50, 50, YELLOW);
          mostra_off(20, 44);
          valor_botao1 = !valor_botao1;
          botaoCambio (YELLOW, BLACK, BLACK, RED, CYAN);
        }
      } 
      //B2
      if (p.x > 208 & p.x < 228)
      {
        if (valor_botao2 == 0)
        {
          
          tft.fillRoundRect(5, 85, 62, 50, 50, GREEN);
          mostra_on(20, 104);
          valor_botao2 = !valor_botao2;
          botaoCambio (BLACK, GREEN, BLACK, RED, CYAN);
        }
        else
        {
          tft.fillRoundRect(5, 85, 62, 50, 50, GREEN);
          mostra_off(20, 104);
          valor_botao2 = !valor_botao2;
          botaoCambio (BLACK, GREEN, BLACK, RED, CYAN);
        }
      }
      //B3
      if (p.x > 148 & p.x < 175)
      {
        if (valor_botao3 == 0)
        {
          
          tft.fillRoundRect(5, 145, 62, 50, 50, BLUE);
          mostra_on(20, 164);
          valor_botao3 = !valor_botao3;
          botaoCambio (BLACK, BLACK, BLUE, RED, CYAN);
        }
        else
        {
          tft.fillRoundRect(5, 145, 62, 50, 50,  BLUE);
          mostra_off(20, 164);
          valor_botao3 = !valor_botao3;
          botaoCambio (BLACK, BLACK, BLUE, RED, CYAN);
        }
      }
      //B4
      if (p.x > 109 & p.x < 129)
      {
        if (valor_botao4 == 0)
        {
          
          tft.fillRoundRect(5, 205, 62, 50, 50, RED);
          mostra_on(20, 224);
          valor_botao4 = !valor_botao4;
          botaoCambio (BLACK, BLACK, BLACK, RED, CYAN);
        }
        else
        {
          tft.fillRoundRect(5, 205, 62, 50, 50,  RED);
          mostra_off(20, 224);
          valor_botao4 = !valor_botao4;
          botaoCambio (BLACK, BLACK, BLACK, RED, CYAN);
        }
      }
      //B5
      if (p.x > 64 & p.x < 86)
      {
        if (valor_botao5 == 0)
        {
          
          tft.fillRoundRect(5, 265, 62, 50, 50, CYAN);
          mostra_on(20,284);
          valor_botao5 = !valor_botao5;
          botaoCambio (BLACK, BLACK, BLACK, RED, CYAN);
        }
        else
        {
          tft.fillRoundRect(5, 265, 62, 50, 50,  CYAN);
          mostra_off(20,284);
          valor_botao5 = !valor_botao5;
          botaoCambio (BLACK, BLACK, BLACK, RED, CYAN);
        }
      }
    }
  }
}
  
void mostra_on(int x, int y)
{
  tft.setTextColor(WHITE);
  tft.setCursor(x, y);
  tft.println("ON");
  delay(100);
}
  
void mostra_off(int x, int y)
{
  tft.setTextColor(WHITE);
  tft.setCursor(x, y);
  tft.println("OFF");
  delay(100);
}

Okay. In this code-chunk, the pins defined seem to indicate one board type (pin location), and the "comment" is calling out another board type (pin location). Are you using the defined board (as written), or the "comment" board (and maybe need to change the code to reflect the "comment" pins) ... and are the pins correctly wired?

#define YP A1 // Y+ is on Analog1 (use A3 para o 9341)
#define XM A2 // X- is on Analog2 (use A2 para o 9341)
#define YM 7 // Y- is on Digital7 (use 9 para o 9341)
#define XP 6 // X+ is on Digital6 (use 8 para o 9341)

yes i believe this are the pins my Uno useing in this order

Your XP might be tied to the wrong pin type... Your XP is tied to D6 (see the following .H code), saying X+ must be analog:

    @brief Construct a new Touch Screen object
    @param xp X+ pin. Must be an analog pin
    @param yp Y+ pin. Must be an analog pin
    @param xm X- pin. Can be a digital pin
    @param ym Y- pin. Can be a digital pin
    @param rx The resistance in ohms between X+ and X- to calibrate pressure sensing

Maybe this? Be sure to re-wire to follow the code...

#define YP A1 // Y+ is on Analog1 (use A3 para o 9341)
#define XP A2 // X+ is on Analog2 (use 8 para o 9341)
//#define XM A2 // X- is on Analog2 (use A2 para o 9341)
#define XM 6 // X- is on Digital6 (use A2 para o 9341)
#define YM 7 // Y- is on Digital7 (use 9 para o 9341)
// #define XP 6 // X+ is on Digital6 (use 8 para o 9341)

This shield Uses digital pins 5-13 and analog 0-3. That means one can use digital pins 2, 3 and analog 4 and 5. Pin 12 is available if not using the micro SD

and i have not wired any relays or made any circuit yet,, i have a relay modul with a single relay on it i can try out stuff on for now,,

Okay. Ensure XP and YP are using Analog pins as the .H file instructs.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.