1.8" TFT LCD, Adafruit_ST7735

Hello all,

I'm trying to make a simple counter, but every time I pressed the button to make it count, the next number print on top of the previous one.

void loop() {
  
 if(digitalRead(switch_1) == LOW)   // if SWITCH_1 is pressed perform action described in loop 
  { tone(BUZZER, 900, 100);    //when button is pressed, the buzzer sounds
        delay(100);
        digitalWrite(BUZZER,LOW);  //no buzzer when button is release     
    count_1++; 
    tft.setCursor(2, 30);
    tft.setTextSize(1);
    tft.setTextColor(ST7735_RED);
    tft.println(count_1,0);
    tft.setCursor(135, 30);
    tft.setTextSize(1);

example

Specify the background colour e.g.

    tft.setTextColor(ST7735_RED, ST7735_BLACK);

You need to print the text with background switched on, e.g.:

tft.setTextColor(ST7735_RED, ST7735_BLACK);

If shorter length strings are printed over longer ones then you need to overprint the extra character with a "space".

You can use dtostrf() to format numbers with spaces already inserted.

Edit: I see David got there first! I must learn to type faster :slight_smile: