I wanted to draw alternating lines on LCD. I can do one line with
for (x2 = 0; x2 < 320, x2 += 2); tft.drawLine(x1, y1, x2, y2, color1);
but how can I make it do another draw a second color at current x2 + 1? If I tried on the same line, the second part seems to be ignored. If I move it to next line, it ends up outside for loop.
nm ended up using while(x2 < 320); instead
If I tried on the same line, the second part seems to be ignored. If I move it to next line, it ends up outside for loop.
No surprise there.
Put { and } round code to be executed in a for loop even if there is only one command. C and C++ don't care that the code is on the same line as the for loop.
(for int x = 0; x < something; x++)
{
//run this code
//and run this code
}
That helps for next time!
Note that I put each { and } on their own line. This is not necessary, but as you can see it makes the code block stand out. Do the same for while loop and if/else tests and actions.