|
| 1 | +/******************************************************************************************* |
| 2 | + * Autor: Fco. Javier Rodriguez Navarro |
| 3 | + * WEB: www.pinguytaz.net |
| 4 | + * |
| 5 | + * Descripción: Ejemplo de uso de la pantalla TFT ST7735 mediante SPI. |
| 6 | + * |
| 7 | + * Libreria: Adafruit-ST7735 |
| 8 | + ***************************************************************************************************/ |
| 9 | +#include <Adafruit_GFX.h> // Nucleo de la libreria |
| 10 | +#include <Adafruit_ST7735.h> // Hardware ST7735 |
| 11 | +#include <SPI.h> // Comunicacion SPI, por el que se comunica el Display. |
| 12 | + |
| 13 | + |
| 14 | +#if defined(ESP32) // ESP32 |
| 15 | + #define TFT_CS 5 // Selector (HSPI_MOSI 15) |
| 16 | + #define TFT_MOSI 23 // Datos de salida (HSPI_MOSI 13) |
| 17 | + #define TFT_SCLK 18 // Reloj (HSPI_MOSI 14) |
| 18 | + |
| 19 | + #define TFT_RST 2 |
| 20 | + #define TFT_DC 4 |
| 21 | +#else // Arduino |
| 22 | + #define TFT_CS 10 // Selector |
| 23 | + #define TFT_MOSI 11 // Datos de salida |
| 24 | + #define TFT_SCLK 13 // Reloj |
| 25 | + |
| 26 | + #define TFT_RST 9 |
| 27 | + #define TFT_DC 8 |
| 28 | + |
| 29 | +#endif |
| 30 | + |
| 31 | +// 1.8" TFT con ST7735: |
| 32 | +//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); |
| 33 | +Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); |
| 34 | + |
| 35 | + |
| 36 | +void setup() |
| 37 | +{ |
| 38 | + #if defined(ESP32) |
| 39 | + Serial.begin(115200); |
| 40 | + #else |
| 41 | + Serial.begin(9600); |
| 42 | + #endif |
| 43 | + |
| 44 | + Serial.print(F("Inicio Test ST7735S")); |
| 45 | + |
| 46 | + // Inicializamos la pantalla |
| 47 | + tft.initR(INITR_BLACKTAB); |
| 48 | + |
| 49 | + |
| 50 | +} |
| 51 | + |
| 52 | +void loop() |
| 53 | +{ |
| 54 | + // Uso de TEXTO |
| 55 | + tft.fillScreen(ST77XX_BLUE); // Ponemos Fondo Azul y limpiamos pantalla |
| 56 | + |
| 57 | + tft.setRotation(3); // Definimos que se escriba de aabajo arriba |
| 58 | + tft.setTextSize(1); // Tamaño del texto de 1-5 |
| 59 | + tft.setCursor(0,100); // Posicion del Cursor,x,y |
| 60 | + tft.setTextColor(ST77XX_GREEN,ST77XX_RED); // Color del texto y fondo |
| 61 | + tft.print("Texto de abajo arriba"); |
| 62 | + |
| 63 | + tft.setRotation(0); // Define como escribira (0 Normal, 1 90 Grados, 2 180 y 3 270 Grados) |
| 64 | + tft.setCursor(0,0); // Posicion del Cursor,x,y |
| 65 | + tft.setTextColor(ST77XX_YELLOW); // Color del texto |
| 66 | + tft.println("Prueba de ST7735"); |
| 67 | + tft.setTextColor(ST77XX_RED); // Color del texto |
| 68 | + tft.setTextSize(2); // Tamaño del texto de 1-5 |
| 69 | + tft.println("Otra linea"); |
| 70 | + tft.setTextSize(1,2); // Tamaño del texto de 1-5 el ancho y el alto |
| 71 | + tft.println("Ancho: "+ String(tft.width())); // Da el ancho |
| 72 | + tft.println("Alto: "+ String(tft.height())); // Da el alto de la pantalla |
| 73 | + |
| 74 | + delay(10000); |
| 75 | + |
| 76 | + // Dibujo de lineas |
| 77 | + tft.fillScreen(ST77XX_RED); |
| 78 | + tft.setRotation(0); |
| 79 | + tft.setCursor(0,0); // Posicion del Cursor,x,y |
| 80 | + tft.setTextSize(3); |
| 81 | + tft.setTextColor(ST77XX_YELLOW); // Color del texto |
| 82 | + tft.println("Lineas"); |
| 83 | + |
| 84 | + tft.drawFastVLine(10,30,66,ST77XX_CYAN); // Horizontal x,y, longitud y color |
| 85 | + tft.drawFastHLine(10,30,66,ST77XX_BLUE); // Linea vertical x,y,longitud,color |
| 86 | + tft.drawLine(0,0,50,100,ST77XX_MAGENTA); // Linea de x,y a x2,y2 y color |
| 87 | + delay(10000); |
| 88 | + |
| 89 | + // Dibujo figuras geometricas |
| 90 | + tft.fillScreen(ST77XX_BLACK); // Negro |
| 91 | + tft.setRotation(0); |
| 92 | + tft.setCursor(0,0); // Posicion del Cursor,x,y |
| 93 | + tft.setTextSize(2); |
| 94 | + tft.setTextColor(ST77XX_WHITE); // Color del texto |
| 95 | + tft.println("Figuras"); |
| 96 | + |
| 97 | + tft.drawRect(0,20,50,10,ST77XX_BLUE); // Rectangulo x,y,ancho, alto, color |
| 98 | + tft.fillRect(50,20,50,10,ST77XX_BLUE); // Rectangulo relleno |
| 99 | + tft.drawRoundRect(0,35,50,10,2,ST77XX_RED); // Esquinas redondeadas x,y,ancho, alto, radio esquinas, color |
| 100 | + tft.fillRoundRect(50,35,50,10,15,ST77XX_RED); // Igual pero relleno |
| 101 | + tft.drawCircle(15,70,7,ST77XX_GREEN); // Circulo x,y,radio,color |
| 102 | + tft.fillCircle(50,70,10,ST77XX_GREEN); // Circulo relleno. |
| 103 | + tft.drawTriangle(0,150,50,150,10,90,ST77XX_BLUE); // Triangulo indicando las esquinas y color |
| 104 | + tft.fillTriangle(50,150,80,150,10,90,ST77XX_ORANGE); // Triangilño relleno |
| 105 | + |
| 106 | + delay(10000); |
| 107 | +} |
0 commit comments