Multi ciolor lines on tft screen

HI
On the screen I can draw different colors lines by switching the case number, each case starts with blank blue screen. How to make drawing lines in different colors on the same screen withouth erasing previois lines ?

this is what I have

image

this is what I need

#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>

#define TFT_MOSI 23  // Data out
#define TFT_SCLK 18  // Clock out

#define TFT_CS   22// // Chip select pin
#define TFT_DC    21 // Data/Command pin
#define TFT_RST   -1  // pin# 2

// Create an instance of the display driver
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
int DCX1, DCX2, DCY1, DCY2;
byte lastButtonState = LOW;
int botonState = 0;

void setup() {
  Serial.begin(115200);

  tft.init(170, 320);
  tft.setRotation(3); // Adjust rotation as needed (0-3),0 = viertical, 1= horyzontal upside down, 2= viertical 180 deg , 3=horyzontal normal,

  // Clear the screen
  //tft.fillScreen(ST77XX_BLACK);//++++++++++++++++++++++++++++++++
  tft.fillScreen(ST77XX_BLUE);
  tft.setTextWrap(false); // Disable text wrapping
  tft.setTextSize(4);     // Set text size
  // tft.setTextColor(ST77XX_WHITE); // Set text color  +++++++++++++++++++
  tft.setTextColor(ST77XX_YELLOW); // Set text color

}

void loop() {
  DCX1 = analogRead(39);
  //DCX1 = map(DCX1, 0, 4096, 0, 3300);
  DCX1 = map(DCX1, 0, 4096, 0, 1600);
  // DCX1 = DCXp(DCX1, 0, 4096, 0, 500);
  //DCX2 = 3299 - DCX1;
  DCX2 = 1600 - DCX1;

  DCY1 = analogRead(36);
  //DCY1 = analogRead(39);
  // DCY1 = map(DCY1, 0, 4096, 0, 3300);
  DCY1 = map(DCY1, 0, 4096, 0, 1600);
  DCY2 = 3299 - DCY1;
  DCY2 = 1600 - DCY1;
  // tft.setCursor(10, 50); // Set cursor position (x, y)
  // tft.print("Hello World!");
  Serial.println( "Hello World");
  
  if (digitalRead(2) == 0)
  {
    // botonState = (botonState + 1) % 4;
    botonState = (botonState + 1) % 7;
    tft.fillScreen(ST77XX_BLUE);
    delay (200);
  }
  switch (botonState)
  {
    case 0:
      tft.setCursor(10, 0); // Set cursor position (x, y)
      tft.print("0");
      tft.fillRect(150 + (DCX1 / 23), 150 - (DCY1 / 23), 3 , 3, ST77XX_WHITE);
      break;

    case 1:
      tft.setCursor(10, 0); // Set cursor position (x, y)
      tft.print("1");
      tft.fillRect(150 + (DCX1 / 23), 150 - (DCY1 / 23), 3 , 3, ST77XX_GREEN);
      break;

    case 2:
      tft.setCursor(10, 0); // Set cursor position (x, y)
      tft.print("2");
      tft.fillRect(150 + (DCX1 / 23), 150 - (DCY1 / 23), 3 , 3, ST77XX_RED);
      break;

    case 3:
      tft.setCursor(10, 0); // Set cursor position (x, y)
      tft.print("3");
      tft.fillRect(150 + (DCX1 / 23), 150 - (DCY1 / 23), 3 , 3, ST77XX_GREEN);
      break;

    case 4:
      tft.setCursor(10, 0); // Set cursor position (x, y)
      tft.print("4");
      tft.fillRect(150 + (DCX1 / 23), 150 - (DCY1 / 23), 3 , 3, ST77XX_BLACK);
      break;

    case 5:
      tft.setCursor(10, 0); // Set cursor position (x, y)
      tft.print("5");
      tft.fillRect(150 + (DCX1 / 23), 150 - (DCY1 / 23), 3 , 3, ST77XX_WHITE);
      break;

    case 6:
      tft.setCursor(10, 0); // Set cursor position (x, y)
      tft.print("6");
      tft.fillRect(150 + (DCX1 / 23), 150 - (DCY1 / 23), 3 , 3, ST77XX_WHITE);
      break;


  }
}

There is no way to overlay (not "erase") lines without the latest color being on top of the other lines, occluding the other lines.

If you offset the "zero" and manage the amplitude of each trace, all traces can be drawn without overlaying. You could add an input (potentiometer, up/down buttons) to move the zero for each trace, giving you the option to overlay or independent.

I don't know what kind of board you're using, or what you're trying to do, but the following code will clear the screen to blue whenever the pin #2 goes LOW.

If the pin #2 is connected to a mechanical switch such as a tactile switch, debouncing will also be necessary.

Thanks, I forgot about that line and added this

  if (digitalRead(14) == LOW)
        {
          tft.fillScreen(ST77XX_BLUE);
        }

now is ok