Hi,
I want to animate the filling of a beer bottle. I have some flickering effect during the "filling" of the neck. I draw two white triangles to shape the bottle which seems to be the flicker reason.
Do you have better ideas ? thank you
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_GREY 0x5AEB
#define LOOP_PERIOD 300 // Display updates every 300 ms
#define TFT_BEER 0xD404 //Couleur biere
uint32_t updateTime = 0; // time for next update
int d = 0;
// Bottle position
int x=150;
int y=70;
int i=0;
// D1 D2 H1 HG H2
// 0 1 2 3 4
int bottle_values[6] = {80, 30, 150, 60, 30};
void setup(void) {
tft.init();
tft.setRotation(2);
Serial.begin(57600); // For debug
tft.fillScreen(TFT_WHITE);
draw_bottle();
updateTime = millis(); // Next update time
}
void loop() {
if (updateTime <= millis()) {
updateTime = millis() + LOOP_PERIOD;
//d est le remplissage virtuel en ml
d += 10;
if (d >= 360)
d = 0;
draw_bottle();
}
}
void draw_bottle(){
int d1=bottle_values[0];
int d2=bottle_values[1];
int h1=bottle_values[2];
int hg=bottle_values[3];
int h2=bottle_values[4];
int ax = x+d1/2-d2/2;
int ay = y;
int bx = x+d1/2+d2/2;
int by = y;
int cx = x+d1/2+d2/2;
int cy = y+h2;
int dx = x+d1;
int dy = y+h2+hg;
int ex = x+d1;
int ey = y+h1+hg+h2;
int fx = x;
int fy = y+h1+hg+h2;
int gx = x;
int gy = y+h2+hg;
int hx = x+d1/2-d2/2;
int hy = y+h2;
//on efface l'ancienne biere
if (d==0)
tft.fillRect(x, y,d1+1 ,h1+hg+h2 , TFT_WHITE);
// Bière
tft.fillRect(x, y+h1+h2+hg-d*(h1+h2+hg)/360,d1+1 , d*(h1+h2+hg)/360, TFT_BEER);
old_beer_y = y+h1+h2+hg-d*(h1+h2+hg)/360;
old_beer_height =d*(h1+h2+hg)/360;
//découpes
tft.fillRect(x, y, d1/2-d2/2, h2, TFT_WHITE);
tft.fillRect(bx, by, 2+d1/2-d2/2, h2, TFT_WHITE);
tft.fillTriangle(x , y + h2, hx , hy , gx, gy, TFT_WHITE);
tft.fillTriangle(cx, cy, 1+cx + d1/2-d2/2, cy,dx,dy, TFT_WHITE);
// Bouteille
tft.drawLine(hx, hy, ax, ay, TFT_BLACK);
tft.drawLine(ax, ay, bx ,by, TFT_BLACK);
tft.drawLine(bx ,by, cx, cy, TFT_BLACK);
tft.drawLine(cx, cy, dx, dy, TFT_BLACK);
tft.drawLine(dx, dy, ex, ey, TFT_BLACK);
tft.drawLine(ex, ey, fx, fy, TFT_BLACK);
tft.drawLine(fx, fy, gx, gy, TFT_BLACK);
tft.drawLine(gx, gy, hx, hy, TFT_BLACK);
}