#include <TFT_eSPI.h> // Biblioteca para a tela TFT
TFT_eSPI tft = TFT_eSPI(); // Inicializa a tela TFT
uint32_t baseColor = 0x190bb8; // Cor base em formato HEX
bool black_bg = true; // Booleano para determinar se o fundo é preto
unsigned long startMillis;
float transitionProgress = 0.0;
bool inTransition = true;
void setup() {
Serial.begin(115200); // Inicializa a comunicação serial
tft.init();
tft.setRotation(1); // Ajuste a rotação conforme necessário
startMillis = millis();
}
void loop() {
// Animação de subida do retângulo e transição do texto
if (inTransition) {
unsigned long currentMillis = millis();
transitionProgress = (float)(currentMillis - startMillis) / 2000.0; // Transição de 2 segundos
if (transitionProgress >= 1.0) {
transitionProgress = 1.0;
inTransition = false;
}
updateUI();
}
// Verifica comandos da Serial para mudar cor
if (Serial.available()) {
String input = Serial.readStringUntil('\n');
input.trim();
if (input.startsWith("c#")) {
String colorHex = input.substring(2);
baseColor = strtol(colorHex.c_str(), NULL, 16);
startMillis = millis();
inTransition = true;
} else if (input.startsWith("bg#")) {
black_bg = input.substring(3).toInt();
updateUI();
}
}
}
float lerpSmooth(float start, float end, float t) {
// Aclive suave usando a função S-curve (t^3 * (t * (t * 6 - 15) + 10))
t = t * t * t * (t * (t * 6 - 15) + 10);
return start + (end - start) * t;
}
uint16_t darkenColor(uint16_t color, float factor) {
uint8_t r = ((color & 0xF800) >> 11) * factor;
uint8_t g = ((color & 0x07E0) >> 5) * factor;
uint8_t b = (color & 0x001F) * factor;
return (r << 11) | (g << 5) | b;
}
void updateUI() {
uint16_t bgColor = black_bg ? TFT_BLACK : darkenColor(baseColor, 0.5);
uint16_t textColor = lerpSmooth(baseColor, TFT_BLACK, transitionProgress);
uint16_t boxColor = baseColor;
tft.fillScreen(bgColor);
// Calcula a posição y do retângulo durante a animação
int rectY = lerpSmooth(240, 80, transitionProgress);
// Desenha o fundo arredondado
tft.fillRoundRect(10, rectY, 220, 80, 30, boxColor);
// Desenha o texto com cor de transição
tft.setTextColor(textColor, boxColor);
tft.setTextSize(4);
tft.setTextDatum(MC_DATUM);
tft.drawString("Wemus Neo", tft.width() / 2, rectY + 40);
}