#include <TFT_eSPI.h>
#include "Icons.h"
#define TWO_TFT
#define SPI_CS1 10
#define SPI_CS2 8
#define SPI_RST 9
#define SPI_DC 4
#define SPI_MOSI 11
#define SPI_SCK 12
#define SPI_LED
#define SPI_MISO 13
#define FRAME_X 210
#define FRAME_Y 180
#define FRAME_W 100
#define FRAME_H 50
#define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W (FRAME_W/2)
#define REDBUTTON_H FRAME_H
#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
#define GREENBUTTON_Y FRAME_Y
#define GREENBUTTON_W (FRAME_W/2)
#define GREENBUTTON_H FRAME_H
// #define ILI9341_BLACK 0x0000 ///< 0, 0, 0
// #define ILI9341_NAVY 0x000F ///< 0, 0, 123
// #define ILI9341_DARKGREEN 0x03E0 ///< 0, 125, 0
// #define ILI9341_DARKCYAN 0x03EF ///< 0, 125, 123
// #define ILI9341_MAROON 0x7800 ///< 123, 0, 0
// #define ILI9341_PURPLE 0x780F ///< 123, 0, 123
// #define ILI9341_OLIVE 0x7BE0 ///< 123, 125, 0
// #define ILI9341_LIGHTGREY 0xC618 ///< 198, 195, 198
// #define ILI9341_DARKGREY 0x7BEF ///< 123, 125, 123
// #define ILI9341_BLUE 0x001F ///< 0, 0, 255
// #define ILI9341_GREEN 0x07E0 ///< 0, 255, 0
// #define ILI9341_CYAN 0x07FF ///< 0, 255, 255
// #define ILI9341_RED 0xF800 ///< 255, 0, 0
// #define ILI9341_MAGENTA 0xF81F ///< 255, 0, 255
// #define ILI9341_YELLOW 0xFFE0 ///< 255, 255, 0
// #define ILI9341_WHITE 0xFFFF ///< 255, 255, 255
// #define ILI9341_ORANGE 0xFD20 ///< 255, 165, 0
// #define ILI9341_GREENYELLOW 0xAFE5 ///< 173, 255, 41
// #define ILI9341_PINK 0xFC18 ///< 255, 130, 198
TFT_eSPI tft1();
#ifdef TWO_TFT
TFT_eSPI tft2(SPI_CS2, SPI_DC);
#endif
int RGBTo565(byte R, byte G, byte B)
{
int ret = (R & 0xF8) << 8; // 5 bits
ret |= (G & 0xFC) << 3; // 6 bits
ret |= (B & 0xF8) >> 3; // 5 bits
return ret;
}
int RGBTo565(long RGB)
{
// R => RGB >> 16 & 0xFF
// G => RGB >> 8 & 0xFF00
// B => RGB & 0xFF
// int ret = (((RGB >> 16) & 0xFF) & 0xF8) << 8; // 5 bits
// ret |= (((RGB >> 8 ) & 0xFF00) & 0xFC) << 3; // 6 bits
// ret |= (((RGB & 0xFF)) & 0xF8) >> 3; // 5 bits
return RGBTo565(((RGB >> 16) & 0xFF), ((RGB >> 8 ) & 0xFF00), (RGB & 0xFF));
}
void drawFrame()
{
tft1.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
#ifdef TWO_TFT
tft2.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_RED);
#endif
}
void redBtn()
{
tft1.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_PINK);
tft1.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
drawFrame();
tft1.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
tft1.setTextColor(ILI9341_WHITE);
tft1.setTextSize(2);
tft1.println("ON");
//RecordOn = false;
#ifdef TWO_TFT
tft2.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE);
tft2.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_YELLOW);
drawFrame();
tft2.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
tft2.setTextColor(ILI9341_PINK);
tft2.setTextSize(2);
tft2.println("ON");
#endif
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S3!");
tft1.begin();
tft1.setRotation(1);
tft1.setCursor(0, 0);
tft1.setTextSize(2);
tft1.setTextColor(ILI9341_YELLOW);
tft1.print("Hola, soy TFT");
tft1.write(0xF7);
tft1.print("C");
Serial.println("TFT1 configurado");
#ifdef TWO_TFT
tft2.begin();
tft2.setRotation(1);
tft2.setCursor(0, 0);
tft2.setTextSize(2);
tft2.setTextColor(ILI9341_YELLOW);
tft2.print("Hola, y yo soy TFT 2");
tft2.write(0xF7);
tft2.print("C");
#endif
tft1.setCursor(0, 60);
tft1.setTextSize(1);
tft1.setTextColor(ILI9341_RED);
tft1.print("Hola, soy rojo y pequeño");
tft1.setTextColor(RGBTo565(255, 165, 0));
tft1.println("Naranja");
tft1.println();
tft1.println(RGBTo565(255, 130, 198));
tft1.println(0xfc18);
#ifdef TWO_TFT
tft2.setCursor(0, 60);
tft2.setTextSize(1);
tft2.setTextColor(ILI9341_ORANGE);
tft2.print("Hola, soy rojo y pequeño");
tft2.setTextColor(RGBTo565(165, 255, 0));
tft2.println("Naranja");
tft2.println();
tft2.println(RGBTo565(130, 255, 130));
tft2.println(0xfc18);
#endif
redBtn();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}