How to draw Fill Triangle using the library Adafruit GFX library?

Hello good day, I’m working with a touch screen, with the Adafruit libraries, the GFX and the MCUFRIEND library, I did some research, and found that to draw a filled triangle the following command is used, "tft.fillTriangle (x1, y1 , x2, y2, x3, y3, Color) “, and I use it in a sketch that I have, but it does not work, I get the following error:” exit status 1, ‘tft’ was not declared in this scope ", I would appreciate your advice, Greetings!

This is the model of my TouchScreen: https://articulo.mercadolibre.com.mx/MLM-613677029-kuman-arduino-uno-r3-de-35-pulgadas-de-pantalla-tactil-tft-_JM

The controller of my TouchScreen is: ILI9486

First off. Make sure that your libraries are up to date via the Library Manager.

I would delete any libraries that came on your CD. Only use libraries from the Library Manager.
i.e. Adafruit_GFX, MCUFRIEND_kbv, TouchScreen

The fillTriangle() method should work. Please post your sketch. I suspect that you just have a typo somewhere.

David.

david_prentice:
First off. Make sure that your libraries are up to date via the Library Manager.

I would delete any libraries that came on your CD. Only use libraries from the Library Manager.
i.e. Adafruit_GFX, MCUFRIEND_kbv, TouchScreen

The fillTriangle() method should work. Please post your sketch. I suspect that you just have a typo somewhere.

David.

Hi, This is my Code:

#include <TouchScreen.h>  //Librería para utilizar el Touch de la Pantalla
#include <Adafruit_GFX.h> //Librería Necesaria
#include <UTFTGLUE.h>     //Librería Necesaria
#include <stdint.h>
#include <Wire.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[]; //Declaramos cuales fuentes vamos a utilizar
extern uint8_t SevenSegNumFont[];
extern uint8_t GroteskBold32x64[];

UTFTGLUE myGLCD(0x9486, A2, A1, A3, A4, A0); //Declaramos el controlador de nuestra pantalla

//Definir pines para controlar la pantalla
#define XP 9  //Pin de control digital
#define YP A2 //Pin análogo de control
#define XM A3 //Pin análogo de control
#define YM 8  //Pin digital de control

//Definir los niveles de presión mínima y máxima
#define MINPRESSURE 10
#define MAXPRESSURE 1000

//Definir los valores para calibrar la pantalla táctil
#define X_STPT 70  //Valor de X inicial
#define X_ENPT 930 //Valor de X final
#define Y_STPT 125 //Valor de Y inicial
#define Y_ENPT 910 //Valor de Y final

TouchScreen myTouch = TouchScreen(XP, YP, XM, YM, 300);

#define NEGRO     0x0000
#define AZUL      0x001F
#define ROJO      0xF800
#define VERDE     0x07E0
#define CIAN      0x07FF
#define MAGENTA   0xF81F
#define AMARILLO  0xFFE0
#define BLANCO    0xFFFF

int color;
int led = 10; //Pin PWM donde va conectado el LED

//Define el ancho y largo de la pantalla en pixeles
int x_size = 480; int y_size = 320;
bool settscrsize (int w, int h) {
  if ((w <= 0) || (h <= 0)) return false;
  x_size = w; y_size = h;
  return true;
}


void LogoSielco(int x1, int y1) {
  myGLCD.setFont(BigFont);
  myGLCD.setColor(ROJO);
  tft.fillTriangle(x1, y1, x1 + 19, y1, x1, y1 + 19,ROJO);
  tft.fillTriangle(x1 + 18, y1 + 1, x1 + 23, y1 - 5, x1 + 12, y1 + 1,ROJO);
  tft.fillTriangle(x1 + 2, y1 + 18, x1 + 4, y1 + 18, x1 + 2, y1 + 14,ROJO);
  tft.fillTriangle(x1 + 3, y1 + 14, x1 + 8, y1 + 14, x1 + 5, y1 + 19,ROJO);
  myGLCD.setColor(NEGRO);
  myGLCD.setBackColor(BLANCO);
  tft.fillTriangle(x1 + 23, y1 + 6, x1 + 23, y1 + 26, x1 + 3, y1 + 26,NEGRO);
  tft.fillTriangle(x1 + 2, y1 + 27, x1 - 1, y1 + 31, x1 + 7, y1 + 27,NEGRO);
  tft.fillTriangle(x1 + 21, y1 + 7, x1 + 18, y1 + 7, x1 + 20, y1 + 10,NEGRO);
  tft.fillTriangle(x1 + 18, y1 + 5, x1 + 13, y1 + 12, x1 + 19, y1 + 12,NEGRO);
  myGLCD.print("Sielco", x1 + 24, y1 + 5, 0);
}

void setup{
  myGLCD.InitLCD(1);
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.setBrightness(0);
  myGLCD.fillScr(BLANCO);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_HI);
}

void loop{
  LogoSielco(180, 80);
}

Please use native GFX methods in new programs.

UTFTGLUE is only for porting legacy UTFT programs.

You should not mix UTFTGLUE methods with the native GFX methods.

You should certainly never create a UTFTGLUE object at the same time as a MCUFRIEND_kbv object.

Just stick with the native tft object MCUFRIEND_kbv object .

If you do not understand, please say.
I am taking my dog out for a walk. I could "correct" your code if you want me to.

David.

david_prentice:
Please use native GFX methods in new programs.

UTFTGLUE is only for porting legacy UTFT programs.

You should not mix UTFTGLUE methods with the native GFX methods.

You should certainly never create a UTFTGLUE object at the same time as a MCUFRIEND_kbv object.

Just stick with the native tft object MCUFRIEND_kbv object .

If you do not understand, please say.
I am taking my dog out for a walk. I could "correct" your code if you want me to.

David.

ok, I would appreciate if you help me to correct my code, I do not understand what you mean by using native gfx methods, could you explain me a little more, or send a link where that is explained? Greetings.

@Campax2,

There were a LOT of syntax errors, bad practice, …
Here is some example code:

#include <MCUFRIEND_kbv.h> //Librería Necesaria
MCUFRIEND_kbv tft;

#include <FreeDefaultFonts.h>   //SmallFont, BigFont, SevenSegFont
#include <Fonts/FreeSerif12pt7b.h> //Free Font that comes with GFX

#define NEGRO     0x0000
#define AZUL      0x001F
#define ROJO      0xF800
#define VERDE     0x07E0
#define CIAN      0x07FF
#define MAGENTA   0xF81F
#define AMARILLO  0xFFE0
#define BLANCO    0xFFFF

int color;
int led = 10; //Pin PWM donde va conectado el LED

//Define el ancho y largo de la pantalla en pixeles
int x_size = 480; int y_size = 320;

bool settscrsize (int w, int h)
{
    if ((w <= 0) || (h <= 0)) return false;
    x_size = w; y_size = h;
    return true;
}


void LogoSielco(int x1, int y1)
{
    // these are all Adafruit_GFX class methods
    tft.setFont(&FreeBigFont);   //note that you use &
    //    tft.setFont(&FreeSerif12pt7b);   //better looking font
    tft.fillTriangle(x1, y1, x1 + 19, y1, x1, y1 + 19, ROJO);
    tft.fillTriangle(x1 + 18, y1 + 1, x1 + 23, y1 - 5, x1 + 12, y1 + 1, ROJO);
    tft.fillTriangle(x1 + 2, y1 + 18, x1 + 4, y1 + 18, x1 + 2, y1 + 14, ROJO);
    tft.fillTriangle(x1 + 3, y1 + 14, x1 + 8, y1 + 14, x1 + 5, y1 + 19, ROJO);
    tft.fillTriangle(x1 + 23, y1 + 6, x1 + 23, y1 + 26, x1 + 3, y1 + 26, NEGRO);
    tft.fillTriangle(x1 + 2, y1 + 27, x1 - 1, y1 + 31, x1 + 7, y1 + 27, NEGRO);
    tft.fillTriangle(x1 + 21, y1 + 7, x1 + 18, y1 + 7, x1 + 20, y1 + 10, NEGRO);
    tft.fillTriangle(x1 + 18, y1 + 5, x1 + 13, y1 + 12, x1 + 19, y1 + 12, NEGRO);
    tft.setTextColor(NEGRO);             //Free Fonts always transparent
    tft.setCursor(x1 + 24, y1 + 5 + 10); //Free Fonts draw from baseline
    // Print class methods from Print.h
    tft.print("Sielco");
}

void setup(void)
{
    // these are MCUFRIEND_kbv methods
    uint16_t ID = tft.readID();
    tft.begin(ID);
    // these are all Adafruit_GFX class methods
    tft.setRotation(1);         //Landscape
    tft.fillScreen(BLANCO);
}

void loop(void)
{
    LogoSielco(180, 80);
}

From the extras/mcufriend_how_to.txt:

MCUFRIEND_kbv inherits all the methods from
the Adafruit_GFX class: Overview | Adafruit GFX Graphics Library | Adafruit Learning System
and Print class: https://www.arduino.cc/en/Serial/Print

The only “new” methods are hardware related:
vertScroll(), readGRAM(), readPixel(), setAddrWindow(), pushColors(), readID(), begin()
readReg(), pushCommand(), WriteCmdData() access the controller registers

I suggest that you try the GFX tutorial.
Please ask questions. Quote which example or tutorial you are having difficulty with.
People are happy to help. (if they know where to look e.g. link or sketch name)

David.

david_prentice:
@Campax2,

There were a LOT of syntax errors, bad practice, …
Here is some example code:

#include <MCUFRIEND_kbv.h> //Librería Necesaria

MCUFRIEND_kbv tft;

#include <FreeDefaultFonts.h>   //SmallFont, BigFont, SevenSegFont
#include <Fonts/FreeSerif12pt7b.h> //Free Font that comes with GFX

#define NEGRO     0x0000
#define AZUL      0x001F
#define ROJO      0xF800
#define VERDE     0x07E0
#define CIAN      0x07FF
#define MAGENTA   0xF81F
#define AMARILLO  0xFFE0
#define BLANCO    0xFFFF

int color;
int led = 10; //Pin PWM donde va conectado el LED

//Define el ancho y largo de la pantalla en pixeles
int x_size = 480; int y_size = 320;

bool settscrsize (int w, int h)
{
   if ((w <= 0) || (h <= 0)) return false;
   x_size = w; y_size = h;
   return true;
}

void LogoSielco(int x1, int y1)
{
   // these are all Adafruit_GFX class methods
   tft.setFont(&FreeBigFont);   //note that you use &
   //    tft.setFont(&FreeSerif12pt7b);   //better looking font
   tft.fillTriangle(x1, y1, x1 + 19, y1, x1, y1 + 19, ROJO);
   tft.fillTriangle(x1 + 18, y1 + 1, x1 + 23, y1 - 5, x1 + 12, y1 + 1, ROJO);
   tft.fillTriangle(x1 + 2, y1 + 18, x1 + 4, y1 + 18, x1 + 2, y1 + 14, ROJO);
   tft.fillTriangle(x1 + 3, y1 + 14, x1 + 8, y1 + 14, x1 + 5, y1 + 19, ROJO);
   tft.fillTriangle(x1 + 23, y1 + 6, x1 + 23, y1 + 26, x1 + 3, y1 + 26, NEGRO);
   tft.fillTriangle(x1 + 2, y1 + 27, x1 - 1, y1 + 31, x1 + 7, y1 + 27, NEGRO);
   tft.fillTriangle(x1 + 21, y1 + 7, x1 + 18, y1 + 7, x1 + 20, y1 + 10, NEGRO);
   tft.fillTriangle(x1 + 18, y1 + 5, x1 + 13, y1 + 12, x1 + 19, y1 + 12, NEGRO);
   tft.setTextColor(NEGRO);             //Free Fonts always transparent
   tft.setCursor(x1 + 24, y1 + 5 + 10); //Free Fonts draw from baseline
   // Print class methods from Print.h
   tft.print(“Sielco”);
}

void setup(void)
{
   // these are MCUFRIEND_kbv methods
   uint16_t ID = tft.readID();
   tft.begin(ID);
   // these are all Adafruit_GFX class methods
   tft.setRotation(1);         //Landscape
   tft.fillScreen(BLANCO);
}

void loop(void)
{
   LogoSielco(180, 80);
}




From the extras/mcufriend_how_to.txt:
I suggest that you try the GFX tutorial.
Please ask questions. Quote which example or tutorial you are having difficulty with.
People are happy to help. (if they know where to look e.g. link or sketch name)

David.

Your code if it worked for me !!

Thanks David, I really appreciate your help, I really do not know how to use Adafruit’s new libraries, I’ll have to start with that, I already had a project built with Rinky Dinky libraries, I had a hard time doing it, but there’s no problem, Now that I changed the screen I will need to start it again, they are like 2,300 lines of code, but in advance thank you so much for helping me to understand more the libraries that I have not used, I would appreciate it if you helped me learn more about the creation of geometric figures, and the use of the touch sensor of the screen, to be able to create touch buttons in my project, Regards!

I suggest that you choose one style or the other.
If you have invested time and effort into the RinkyDink style, you should decide whether to stick with it.

I think that there is more future in the GFX style. And since Serial, LiquidCrystal, ... all use the Print.h style of printing text, you should find it easy.

Just follow tutorials. Run examples. Adapt examples to suit your own project.

Ask for help when you need it.

David.