hendrixb
hendrixb

Reputation: 11

Starting New Rows With Arduino TFT

I am experimenting with writing on a 1.8" TFT Display. I am trying to have the MCU write on each line and have it start a new row after reaching the specified "bottom" of the screen, but it writes to the next row instead of the next line, similar to below.

BlahBlahBlahBlah
Blah
Blah
Blah
Blah
Blah

Whereas I am looking for

BlahBlahBlahBlah
BlahBlahBlahBlah
BlahBlahBlahBlah
BlahBlahBlahBlah
BlahBlahBlahBlah

From what I can tell, the if-statement is not resetting, so the program writes and sets the cursor back to the top in the next row.

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

int lineNumber = 1;
int rowNumber = 1;

void setup(void) 
{

  tft.initR(INITR_BLACKTAB);
  tft.fillScreen(ST77XX_BLACK);

  while (rowNumber <= 5)
  {
    if (lineNumber > 15)
    {
      tft.setCursor(25*rowNumber, 0);
      rowNumber++;
      lineNumber = 1;
    }

    tft.println("Blah");
    lineNumber++;


  }
}

Upvotes: 0

Views: 331

Answers (1)

hendrixb
hendrixb

Reputation: 11

I found a workaround. Rather than using the println() function, I used the print() function and explicitly set the cursor to where I wanted it. Shown below.

 for (int rowNumber = 0; rowNumber <= 4; rowNumber++)
   {
 tft.setCursor(25*rowNumber,0);

for (int lineNumber = 0; lineNumber <= 15; lineNumber++)
     {
  tft.setCursor(25*rowNumber, 7*lineNumber);
  tft.print("blah");

  Serial.println(lineNumber);
     }
   }

Upvotes: 0

Related Questions