#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
// #include "error2.h"
// #include "welcome.h"
// #include "bsod.h"
// #include "frame.h"
TFT_eSPI tft = TFT_eSPI();
#define NEOPIXEL 21
// #define TFT_SCK D2
// #define TFT_MOSI D3
// #define TFT_RST D4
// #define TFT_DC D5
// #define TFT_CS -1
// static int RGB_BRIGHTNESS = 255;
const int transitionTime = 1000; // Time in ms for each transition
const int stepDelay = 10; // Delay between steps (smaller = smoother transition)
const int steps = transitionTime / stepDelay;
const int pwmFreq = 5000;
const int pwmResolution = 8;
const int pwmLedChannelTFT = 5;
bool neoPixelRunning = true;
unsigned long previousMillis = 0;
int currentStep = 0;
void setup() {
Serial.begin(115200);
Serial.println("\n-------- ESP32 Test Started! --------\n");
tft.init();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
// tft.setSwapBytes(true);
// ledcSetup(pwmLedChannelTFT, pwmFreq, pwmResolution);
// ledcAttachPin(17, pwmLedChannelTFT);
ledcWrite(pwmLedChannelTFT, 80);
tft.print("This display is working...");
}
void smoothTransition(int rStart, int gStart, int bStart, int rEnd, int gEnd, int bEnd, int currentStep, int steps) {
int r = rStart + (rEnd - rStart) * currentStep / steps;
int g = gStart + (gEnd - gStart) * currentStep / steps;
int b = bStart + (bEnd - bStart) * currentStep / steps;
rgbLedWrite(NEOPIXEL, r, g, b);
}
void loop()
{
unsigned long currentMillis = millis();
// Handle NeoPixel transitions
if (neoPixelRunning) {
static int currentColor = 0;
static int r1 = RGB_BRIGHTNESS, g1 = 0, b1 = 0;
static int r2 = 0, g2 = RGB_BRIGHTNESS, b2 = 0;
if (currentMillis - previousMillis >= stepDelay) {
previousMillis = currentMillis;
// Update NeoPixel transition step
smoothTransition(r1, g1, b1, r2, g2, b2, currentStep, steps);
currentStep++;
if (currentStep >= steps) {
currentStep = 0;
currentColor = (currentColor + 1) % 4;
// Update target colors for the next transition
switch (currentColor) {
case 0: r1 = RGB_BRIGHTNESS; g1 = 0; b1 = 0; r2 = 0; g2 = RGB_BRIGHTNESS; b2 = 0; break; // Red to Green
case 1: r1 = 0; g1 = RGB_BRIGHTNESS; b1 = 0; r2 = 0; g2 = 0; b2 = RGB_BRIGHTNESS; break; // Green to Blue
case 2: r1 = 0; g1 = 0; b1 = RGB_BRIGHTNESS; r2 = RGB_BRIGHTNESS; g2 = RGB_BRIGHTNESS; b2 = RGB_BRIGHTNESS; break; // Blue to White
case 3: r1 = RGB_BRIGHTNESS; g1 = RGB_BRIGHTNESS; b1 = RGB_BRIGHTNESS; r2 = RGB_BRIGHTNESS; g2 = 0; b2 = 0; break; // White to Red
}
}
}
}
// static unsigned long lastFrameTime = 0;
// static int currentFrame = 0;
// // Handle TFT animations
// if (currentMillis - previousMillis >= 80) { // Adjust the delay for frame updates
// tft.pushImage(52, 56, 150, 151, frame[currentFrame]);
// currentFrame++;
// if (currentFrame >= 12) {
// currentFrame = 0;
// // Switch to next screen when animation finishes
// tft.pushImage(0, 0, 240, 240, welcome);
// delay(5200);
// tft.fillScreen(TFT_BLACK);
// tft.pushImage(40, 50, 160, 102, error2);
// delay(4000);
// tft.pushImage(0, 0, 240, 240, bsod);
// delay(7000);
// tft.fillScreen(TFT_BLACK);
// }
// }
}
Loading
ili9341-cap-touch
ili9341-cap-touch