Text output on lcd12864 with '\n'

I set up text output to the screen, it works, but each new line is shifted by a character x+=6. How can you fix it? :grinning:

char text[] = "Hey Bro!\nI am Console\nOpen source project!";

void frame_3()
{
  int sizeText = sizeof(text); int x{}; int y{10};
  
  for(int i = 0, x = 0; i < sizeText, x < (sizeText*6); i++, x+=6)
  {
    u8g2.setFont(u8g2_font_6x10_tr);
    u8g2.setCursor(x, y);
    u8g2.print(text[i]);

    if (text[i] == '\n') 
    {
      y += 10; x = 0;
    }
  }
  Serial.println(sizeText);
}

What does the end condition in the first for loop evaluate as?

Hmmm I don't quite understand your question.

The first loop counts up to the number of characters in the string.

the second counts with a step of 6 pixels to the result sizeText*6

No, that's why I asked.

Edit: you edited your last response after I had posted mine

So, again,

1 Like

It's already night outside the window and I want to sleep. But once again and again revised the condition :grin: Ooooh Yes! I get it right? :grinning:

    if (text[i] == '\n') 
    {
      y += 10; x = -6;
    }

No, the for loop terminal condition

It's pretty unusual to see a comma in any condition.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.