Linear Meter Tick shadow not transparent with a SPIFFS BMP #1086
Replies: 4 comments 4 replies
-
Post the sketch as a zip file complete with the images. The markdown scrambles pasted code unless you use the triple tick markdown for embedding code. |
Beta Was this translation helpful? Give feedback.
-
Oups,very sorry for the convenience,all is in a folder with the BMP data,with only the working code and |
Beta Was this translation helpful? Give feedback.
-
Thanks to spend some time with my sketch :) TFT_eSPI ver = 2.3.61 Display driver = 9488 TFT_CS = PIN_D8 Font GLCD loaded Display SPI frequency = 20.00 I use a Mini D1 R2, i had the same issue with a 7inch SSD1963 and ESP Wrover |
Beta Was this translation helpful? Give feedback.
-
For the TFT 3.5 or 4.0 i use ILI9488 or ST7796,the two work with this config: #define TFT_CS PIN_D8 // Chip select control pin D8 #define TOUCH_CS PIN_D4 // Chip select pin (T_CS) of touch screen #define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH #define SMOOTH_FONT #define SPI_FREQUENCY 20000000 #define SPI_READ_FREQUENCY 20000000 #define SPI_TOUCH_FREQUENCY 2500000 additional infos: MINI D1 R2 (ESP266) & TFT 480X320( ILI7796 or ILI9488) CS=D8 , DC=D3 , MOSI & T_DIN=D7 |
Beta Was this translation helpful? Give feedback.
-
Hi bodmer, i make some experimentation with SPIFFS BMP and the Linear meter sketch,
i swept away all the things i didn't need ,hope i did it right :),so i kept the essential of the needle tick,but
the problem is that there is always a remanent trace of the moving tick and the transparent colour don't
do anything,here is the custom sketch i did and the photo of the result:
#define FS_NO_GLOBALS
#include <FS.h>
//#define ESP32 //choose esp32 or esp8266
#ifdef ESP32
#include "SPIFFS.h" // For ESP32 only
#endif
// Define meter size as 1 for tft.rotation(0) or 1.5555 for tft.rotation(1)
#define M_SIZE 2
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_GREY 0x5AEB
float ltx = 0; // Saved x coord of bottom of needle
uint16_t osx = M_SIZE120, osy = M_SIZE170; // Saved x & y coords
uint32_t updateTime = 0; // time for next update
int old_analog = -999; // Value last displayed
int value[6] = {0, 0, 0, 0, 0, 0};
int old_value[6] = { -1, -1, -1, -1, -1, -1};
int d = 0;
void setup() {
Serial.begin(115200); // For debug
if (!SPIFFS.begin()) {
Serial.println("SPIFFS initialisation failed!");
while (1) yield(); // Stay here twiddling thumbs waiting
}
Serial.println("\r\nSPIFFS initialised.");
tft.init();
tft.setRotation(3);
//tft.fillScreen(TFT_BLACK);
drawBmp("/vuMetre.bmp", 0, 0);
analogMeter(); // Draw analogue meter
updateTime = millis(); // Next update time
}
void loop() {
if (updateTime <= millis()) {
updateTime = millis() + 20; // Update meter needle every 20 milliseconds
}
}
// #########################################################################
// Draw the analogue meter on the screen
// #########################################################################
void analogMeter()
{
// Meter outline
/*
tft.fillRect(0, 0, M_SIZE239, M_SIZE176, TFT_GREY);
tft.fillRect(5, 3, M_SIZE230, M_SIZE170, TFT_WHITE);
tft.setTextColor(TFT_BLACK); // Text colour
*/
// Draw ticks every 5 degrees from -50 to +50 degrees (100 deg. FSD swing)
for (int i = -50; i < 51; i += 5) {
// Long scale tick length
int tl = 15;
/*
// Yellow zone limits
//if (i >= -50 && i < 0) {
// tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW);
// tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW);
//}
*/
// Short scale tick length
if (i % 25 != 0) tl = 8;
// tft.drawLine(x0, y0, x1, y1, TFT_RED);//arc de cercle decoupé en graduations graduation
/*
// Check if labels should be drawn, with position tweaks / graduation de 25 en 25
if (i % 25 == 0) {
// Calculate label positions
x0 = sx * (M_SIZE100 + tl + 10) + M_SIZE120;
y0 = sy * (M_SIZE100 + tl + 10) + M_SIZE140;
switch (i / 25) {
case -2: tft.drawCentreString("0", x0, y0 - 12, 2); break;
case -1: tft.drawCentreString("25", x0, y0 - 9, 2); break;
case 0: tft.drawCentreString("50", x0, y0 - 7, 2); break;
case 1: tft.drawCentreString("75", x0, y0 - 9, 2); break;
case 2: tft.drawCentreString("100", x0, y0 - 12, 2); break;
}
}
*/
/*
// Now draw the arc of the scale / arc de cercle de la graduation
sx = cos((i + 5 - 90) * 0.0174532925);
sy = sin((i + 5 - 90) * 0.0174532925);
x0 = sx * M_SIZE100 + M_SIZE120;
y0 = sy * M_SIZE100 + M_SIZE140;
// Draw scale arc, don't draw the last part
if (i < 50) tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
*/
}
/*
tft.drawString("%RH", M_SIZE*(5 + 230 - 40), M_SIZE*(119 - 20), 2); // Units at bottom right
tft.drawCentreString("%RH", M_SIZE120, M_SIZE70, 4); // Comment out to avoid font 4
tft.drawRect(5, 3, M_SIZE230, M_SIZE119, TFT_BLACK); // Draw bezel line
*/
plotNeedle(0, 0); // Put meter needle at 0
}
// #########################################################################
// Update needle position
// This function is blocking while needle moves, time depends on ms_delay
// 10ms minimises needle flicker if text is drawn within needle sweep area
// Smaller values OK if text not in sweep area, zero for instant movement but
// does not look realistic... (note: 100 increments for full scale deflection)
// #########################################################################
void plotNeedle(int value, byte ms_delay)
{
// rectangle de visualisation de la valeur d'entrée
tft.setTextColor(TFT_YELLOW, TFT_BLUE);
char buf[8]; dtostrf(value, 5, 0, buf);
tft.drawRightString(buf, M_SIZE52, M_SIZE(143 - 20), 6);
if (value < -10) value = -10; // Limit value to emulate needle end stops
if (value > 110) value = 110;
// Move the needle until new value reached
while (!(value == old_analog)) {
if (old_analog < value) old_analog++;
else old_analog--;
/*
// Re-plot text under needle
tft.setTextColor(TFT_BLACK);
tft.drawCentreString("%RH", M_SIZE120, M_SIZE70, 4); // // Comment out to avoid font 4
*/
}
}
Is there a way to make a sprite really transparent over a BMP when and where i want it?
Beta Was this translation helpful? Give feedback.
All reactions