Replace delay inside of function

I'm displaying lines on a tft LED screen using a for loop..
Ive read many of the blink without delay tutorials but none seem to fit my needs here or I'm just not getting it.
example code below..

for(int i = 0; i<=34; i++){
tft.drawLine(i, y,x2, y2, TFT_YELLOW);

Now before I display the next 'i' I must erase the previous Line with a delay(22)..

delay(22);  //this prevents screen flicker

tft.drawLine(i, y,x2, y2, TFT_BLACK);

I've been trying to implement millis to replace the delay but am not having much success.
My code will run in

void loop()

but the delay is stopping other functions from running during the delay(22) period.
Where do I place the standard millis code in my function?
Thanks

We can't see your code, but the for loop has to go

You should use a millis timer in your main function.
If the timer is due: erase last line, update i, draw new line. First line can be drawn without timer.

Ok thanks for the quick reply. I'll try that now :slight_smile:

Ok I will recode and use an 'if' statement.
Thanks

Thank you. Your info made it work :+1:

Great! Good luck with your project!

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