Hi there,
SO, Super Citric Fly’s in and Saves the DAY… NICE one Working Good Here.!
Here is my successful code demo and it works for both the C3 or C6 without edit.
I loaded some older code too and it worked without using the older TFT_eSPI lib, ver 2.5.23
Very Good!
I have not tested it in conjunction with WiFi or BLE I’ll try that next.
" this is a gauge demo with a Pointer value in the center (after the scrolling text)"
Compiler output and Serial output bellow.
New ROLex…
Gauge Demo
//This will make the meter visually alert you when the reading crosses 45, with both the gauge and the displayed number turning red.
//
// TFT_eSPI.h Version [email protected], updated from https://github.com/Seeed-Projects/SeeedStudio_TFT_eSPI
// BSP is 3.0.5
// Xiao ESP32C6 AOK :-)
// tested 10/14/24 by PJ Glasso
//
#include <SPI.h>
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define YELLOW 0xFFE0
#define GREY 0x2108
#define TEXT_COLOR 0xFFFF
#define SCALE0 0xC655
#define SCALE1 0x5DEE
#define DEG2RAD 0.0174532925
int xpos = 0;
int ypos = 0;
int gap = 55;
int radius = 120;
int angle;
uint32_t runTime = -99999;
int reading;
int d = 0;
bool range_error = 0;
float rt_x, rt_y, rl_x, rl_y, rr_x, rr_y;
float rt_x_old, rt_y_old, rl_x_old, rl_y_old, rr_x_old, rr_y_old;
float angle_top, angle_rechts, angle_links;
float center_x = 120;
float center_y = 125;
float temp_00;
uint32_t chipId = 0;
void setup(void) {
tft.begin();
Serial.begin(9600);
delay (2000);
Serial.println( "Starting UP , Round Display Test...");
Serial.println();
for(int i=0; i<17; i=i+8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
Serial.printf("This chip has %d cores\n", ESP.getChipCores());
Serial.print("Chip ID: "); Serial.println(chipId);
tft.setRotation(0);
tft.fillScreen(BLACK);
// Scroll "PJ_Seeed" message in the center for 20 seconds
scrollText("PJ_Seeed", BLUE, 10 * 1000); // Display for 20 seconds
tft.fillScreen(BLACK); // Clear the screen
}
void loop() {
if (millis() - runTime >= 0L) {
runTime = millis();
temp_00 = random(00, 100); // Simulate random value for testing
reading = temp_00;
indexTag(); // Update the index tag
if (reading > 45) {
ringMeter(reading, 0, 100, xpos, ypos, radius, RED); // Red gauge if reading > 90
drawText(String(reading), 120, 125, RED); // Red font if reading > 90
} else {
ringMeter(reading, 0, 100, xpos, ypos, radius, GREEN); // Green gauge for normal range
drawText(String(reading), 120, 125, WHITE); // White font for normal range
}
delay(1000); // Wait before next update
}
}
// Function to scroll text across the screen
void scrollText(String text, uint16_t color, uint32_t duration) {
uint32_t startTime = millis();
int textWidth = tft.textWidth(text);
int xStart = tft.width(); // Start the text off the screen (right side)
int xEnd = -textWidth; // End when the text is completely off the screen (left side)
while (millis() - startTime < duration) {
int xPos = map(millis() - startTime, 0, duration, xStart, xEnd);
tft.fillScreen(BLACK); // Clear the screen
tft.setTextColor(color, BLACK);
tft.setTextSize(2); // Adjust text size as needed
tft.setCursor(xPos, tft.height() / 2 - 10); // Center the text vertically
tft.print(text);
delay(250); // Control the scroll speed
}
}
void drawText(String value, int x, int y, uint16_t color) {
// Clear a large enough area where the previous text was displayed (with background color)
int16_t textWidth = tft.textWidth("000"); // Estimate the maximum width for a 3-digit number
int16_t textHeight = 24; // Adjust based on text size
// Fill the area with the background color (BLACK) to ensure old digits are cleared
tft.fillRect(x - (textWidth / 2), y, textWidth, textHeight, BLACK);
// Set the new text color and print the new value
tft.setTextColor(color, BLACK); // Set text color with background as BLACK
tft.setTextSize(3); // Adjust text size as needed
tft.setCursor(x - (tft.textWidth(value) / 2), y); // Center the text
tft.print(value); // Display the new value
}
// Draw the meter on the screen
int ringMeter(int value, int vmin, int vmax, int x, int y, int r, uint16_t scheme) {
x += r;
y += r;
int w = r / 3;
angle = 150;
int v = map(value, vmin, vmax, -angle, angle);
byte seg = 3;
byte inc = 6;
for (int i = -angle + inc / 2; i < angle - inc / 2; i += inc) {
float sx = cos((i - 90) * DEG2RAD);
float sy = sin((i - 90) * DEG2RAD);
uint16_t x0 = sx * (r - w) + x;
uint16_t y0 = sy * (r - w) + y;
uint16_t x1 = sx * r + x;
uint16_t y1 = sy * r + y;
float sx2 = cos((i + seg - 90) * DEG2RAD);
float sy2 = sin((i + seg - 90) * DEG2RAD);
int x2 = sx2 * (r - w) + x;
int y2 = sy2 * (r - w) + y;
int x3 = sx2 * r + x;
int y3 = sy2 * r + y;
if (i < v) {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, scheme);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, scheme);
} else {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, GREY);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, GREY);
}
}
return x + r;
}
// Draw the index tag
void indexTag() {
tft.fillTriangle(rt_x_old, rt_y_old, rl_x_old, rl_y_old, rr_x_old, rr_y_old, BLACK);
angle_top = -(240 * DEG2RAD) + ((3 * temp_00) * DEG2RAD);
angle_links = (angle_top - (6 * DEG2RAD));
angle_rechts = (angle_top + (6 * DEG2RAD));
rt_x = (center_x + ((radius - 45) * cos(angle_top)));
rt_y = (center_y + ((radius - 45) * sin(angle_top)));
rl_x = (center_x + ((radius - 60) * cos(angle_links)));
rl_y = (center_y + ((radius - 60) * sin(angle_links)));
rr_x = (center_x + ((radius - 60) * cos(angle_rechts)));
rr_y = (center_y + ((radius - 60) * sin(angle_rechts)));
rt_x_old = rt_x;
rt_y_old = rt_y;
rl_x_old = rl_x;
rl_y_old = rl_y;
rr_x_old = rr_x;
rr_y_old = rr_y;
tft.fillTriangle(rt_x, rt_y, rl_x, rl_y, rr_x, rr_y, YELLOW);
}
Compiler output that counts…
FQBN: esp32:esp32:XIAO_ESP32C6
Using board 'XIAO_ESP32C6' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5
Using core 'esp32' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5
EDIT--- For ___Brevity...
Using library SPI at version 3.0.5 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5\libraries\SPI
Using library TFT_eSPI at version 2.5.43 in folder: D:\Arduino_projects\libraries\TFT_eSPI
Using library FS at version 3.0.5 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5\libraries\FS
Using library SPIFFS at version 3.0.5 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5\libraries\SPIFFS
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp-rv32\\2302/bin/riscv32-esp-elf-size" -A "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\02E327668A7C72E8CA85338770FE5BA0/sketch_oct14a_scroll_pjg_C6_round_eye.ino.elf"
Sketch uses 272642 bytes (20%) of program storage space. Maximum is 1310720 bytes.
Global variables use 13208 bytes (4%) of dynamic memory, leaving 314472 bytes for local variables. Maximum is 327680 bytes.
Serial output…
Starting UP , Round Display Test...
ESP32 Chip model = ESP32-C6 Rev 1
This chip has 1 cores
Chip ID: 16776721
HTH
GL PJ