/*
Layout com textos SET e OUT menores
*/
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//========= Variáveis de controle ========================
// CH1
float Iset_ch1 = 2.00; // Corrente configurada (A)
float Vset_ch1 = 5.00; // Tensão configurada (V)
float Iout_ch1 = 0.00; // Corrente de saída (A)
float Vout_ch1 = 0.00; // Tensão de saída (V)
float Wat_ch1 = Iset_ch1 * Vset_ch1; // Potência configurada (W)
float Wout_ch1 = Iout_ch1 * Vout_ch1; // Potência de saída (W)
String CC_ch1 = "CC"; // Modo de operação
String Liga_ch1 = "ON"; // Estado ligado/desligado
String Memory_ch1 = "M0"; // Memória
// CH2
float Iset_ch2 = 10.00;
float Vset_ch2 = 5.00;
float Iout_ch2 = 0.00;
float Vout_ch2 = 0.00;
float Wat_ch2 = Iset_ch2 * Vset_ch2;
float Wout_ch2 = Iout_ch2 * Vout_ch2;
String CC_ch2 = "CC";
String Liga_ch2 = "ON";
String Memory_ch2 = "M0";
//====================================================
void setup() {
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
int spacing = 5;
int topHeight = 150;
int bottomHeight = 70;
int halfWidth = (320 - spacing) / 2;
// Fonte para títulos
tft.setTextSize(2);
tft.setTextColor(ILI9341_BLACK);
int16_t x1, y1; uint16_t w, h;
// --- CH1 (azul) ---
tft.drawRoundRect(0, 0, halfWidth, topHeight, 10, ILI9341_BLUE);
tft.fillRoundRect(0, 0, halfWidth, 30, 10, ILI9341_BLUE);
tft.fillRect(0, 15, halfWidth, 15, ILI9341_BLUE);
tft.getTextBounds("CH1", 0, 0, &x1, &y1, &w, &h);
tft.setCursor((halfWidth - w) / 2, (30 - h) / 2);
tft.print("CH1");
int smallHeight = topHeight * 0.2;
int rectY = 40;
tft.drawRect(8, rectY, halfWidth - 16, smallHeight, ILI9341_BLUE);
tft.drawRect(8, rectY + smallHeight + 5, halfWidth - 16, topHeight - smallHeight - 55, ILI9341_BLUE);
// Texto SET
tft.setTextSize(1);
tft.setTextColor(ILI9341_BLUE);
tft.setCursor(12, rectY + 5);
tft.print("SET");
// Valores Iset/Vset centralizados no quadrado menor
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
String textoCH1 = String(Iset_ch1, 2) + "A " + String(Vset_ch1, 2) + "V";
tft.getTextBounds(textoCH1, 0, 0, &x1, &y1, &w, &h);
int posX = (halfWidth - w) / 2;
int posY = rectY + (smallHeight - h) / 2; // centralizado verticalmente
tft.setCursor(posX, posY);
tft.print(textoCH1);
// Traço azul exatamente abaixo do texto
tft.drawLine(posX, posY + h + 2, posX + w, posY + h + 2, ILI9341_BLUE);
// Potência configurada no canto inferior direito
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(halfWidth - 45, rectY + smallHeight - 12);
tft.print(String(Wat_ch1, 2) + "W");
// --- CH2 (amarelo) ---
tft.setTextSize(2);
tft.setTextColor(ILI9341_BLACK);
tft.drawRoundRect(halfWidth + spacing, 0, halfWidth, topHeight, 10, ILI9341_YELLOW);
tft.fillRoundRect(halfWidth + spacing, 0, halfWidth, 30, 10, ILI9341_YELLOW);
tft.fillRect(halfWidth + spacing, 15, halfWidth, 15, ILI9341_YELLOW);
tft.getTextBounds("CH2", 0, 0, &x1, &y1, &w, &h);
tft.setCursor(halfWidth + spacing + (halfWidth - w) / 2, (30 - h) / 2);
tft.print("CH2");
smallHeight = topHeight * 0.2;
rectY = 40;
tft.drawRect(halfWidth + spacing + 8, rectY, halfWidth - 16, smallHeight, ILI9341_YELLOW);
tft.drawRect(halfWidth + spacing + 8, rectY + smallHeight + 5, halfWidth - 16, topHeight - smallHeight - 55, ILI9341_YELLOW);
// Texto SET
tft.setTextSize(1);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(halfWidth + spacing + 12, rectY + 5);
tft.print("SET");
// Valores Iset/Vset centralizados no quadrado menor
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
String textoCH2 = String(Iset_ch2, 2) + "A " + String(Vset_ch2, 2) + "V";
tft.getTextBounds(textoCH2, 0, 0, &x1, &y1, &w, &h);
posX = halfWidth + spacing + (halfWidth - w) / 2;
posY = rectY + (smallHeight - h) / 2; // centralizado verticalmente
tft.setCursor(posX, posY);
tft.print(textoCH2);
// Traço amarelo exatamente abaixo do texto
tft.drawLine(posX, posY + h + 2, posX + w, posY + h + 2, ILI9341_YELLOW);
// Potência configurada no canto inferior direito
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(halfWidth + spacing + halfWidth - 45, rectY + smallHeight - 12);
tft.print(String(Wat_ch2, 2) + "W");
// --- CH3 (verde) ---
tft.setTextSize(2);
tft.setTextColor(ILI9341_BLACK);
tft.drawRoundRect(0, topHeight + spacing, 320, bottomHeight, 10, ILI9341_GREEN);
tft.fillRoundRect(0, topHeight + spacing, 320, 30, 10, ILI9341_GREEN);
tft.fillRect(0, topHeight + spacing + 15, 320, 15, ILI9341_GREEN);
tft.getTextBounds("CH3", 0, 0, &x1, &y1, &w, &h);
tft.setCursor((320 - w) / 2, topHeight + spacing + (30 - h) / 2);
tft.print("CH3");
}
void loop() {
// Nada aqui
}