简体   繁体   中英

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++;


  }
}

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);
     }
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM