Hello everybody
after some time I am back to discuss a programming problem which appears because I do not have enough experience in C/C++. First of all here is my code:
// TEST seven segment display on TFT
// XIAO ESP32-C3 Supermini
// May 2026
// Bernardo Gullasch
// including Wifi, TFT-Display, Setbuttons
/* TFT_eSPI parameters ILI9341 240x320 2,4inch
* #define ILI9341_DRIVER // Generic driver for common displays
* #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
* #define TFT_HEIGHT 320 // ST7789 240 x 320
* #define TFT_INVERSION_OFF
*
* #define TFT_MISO D9
#define TFT_MOSI D10
#define TFT_SCLK D8
#define TFT_CS D7 // Chip select control pin
#define TFT_DC D3 // Data Command control pin
#define TFT_RST D2 // Reset pin (could connect to RST pin)
*/
#include <TFT_eSPI.h>
#include <SPI.h>
#include <WiFi.h>
#include <time.h>
#include <ESP32Time.h>
#include "FreeFonts.h"
#define TFT_BLACK 0x0000
#define TFT_WHITE 0xFFFF
#define TFT_LIGHTGREY 0xBDF7
#define TFT_DARKGREY 0x7BEF
#define TFT_RED 0xF800
#define TFT_YELLOW 0xFFE0
#define TFT_BLUE 0x1F
#define SetBtn 3
#define UpBtn 6 //4
#define DwnBtn 7 //5
#define TFT_LED 2
// Use hardware SPI
TFT_eSPI tft = TFT_eSPI();
bool Led = HIGH;
int colors = 0;
// seven segment relative coordinates
int x = 50;
int y = 40;
int xoff = 45; // offset for repositioning
int yoff = 0; // offset for repositioning
int lx = 40; // length of segment
int ly = 40; // length of segment
int z = 4; // space between segments and segment line thickness
// segments drawing parameters for the tft.fillRoundRect statement
int a[4] = {x+lx-z, y+z, 2*z, ly-2*z};
int b[4] = {x+lx-z, y+ly+z, 2*z, ly-2*z};
int c[4] = {x+z, y+2*ly-z, lx-2*z, 2*z};
int d[4] = {x-z, y+ly+z, 2*z, ly-2*z};
int e[4] = {x-z, y+z, 2*z, ly-2*z};
int f[4] = {x+z, y-z, lx-2*z, 2*z};
int g[4] = {x+z, y+ly-z, lx-2*z, 2*z};
int seg[7][4] = {
{a[0],a[1],a[2],a[3]},
{b[0],b[1],b[2],b[3]},
{c[0],c[1],c[2],c[3]},
{d[0],d[1],d[2],d[3]},
{e[0],e[1],e[2],e[3]},
{f[0],f[1],f[2],f[3]},
{g[0],g[1],g[2],g[3]}
};
// --------- SETUP ---------
void setup()
{
pinMode(TFT_LED, OUTPUT);
pinMode(SetBtn, INPUT_PULLUP);
pinMode(UpBtn, INPUT_PULLUP);
pinMode(DwnBtn, INPUT_PULLUP);
digitalWrite(TFT_LED, Led);
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_LIGHTGREY);
}
// --------------------- finish Setup ------------------------
void loop()
{
print7seg();
}
// ------------------------------------- End Loop ------------------------------
void print7seg()
{
for(int shift=0; shift<4; shift++)
{
a[0]=a[0]+shift*xoff; a[1]=a[1]+shift*yoff;
b[0]=b[0]+shift*xoff; b[1]=b[1]+shift*yoff;
c[0]=c[0]+shift*xoff; c[1]=c[1]+shift*yoff;
d[0]=d[0]+shift*xoff; d[1]=d[1]+shift*yoff;
e[0]=e[0]+shift*xoff; e[1]=e[1]+shift*yoff;
f[0]=f[0]+shift*xoff; f[1]=f[1]+shift*yoff;
g[0]=g[0]+shift*xoff; g[1]=g[1]+shift*yoff;
for(int i=0; i<7; i++)
{
tft.fillRoundRect(seg[i][0],seg[i][1],seg[i][2],seg[i][3],z,TFT_BLUE);
}
}
}
to make it short, this should print the number 8 in seven segment format on my TFT display at the position x,y. and repeat this 3 times with a position offset of (i*xoff), (i*yoff) which result from the "i" loop . The code compiles good but it draws only the first digit on the display. This looks like the values of the segment drawing parameters do not update.
what is wrong with my code ???
thanks in advance