I have simple example, where in loop is called webServer to handle clients and also text drawing on display. The thing is that webServer is not responding, but when I remove second part of loop - drawing text to display then web server starts to work normally.
Server does not respond:
void loop() {
server.handleClient();
unsigned long timeNow = millis();
if ((timeNow > screenChangeTime)) {
display.clear();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(12, 20,"Loaded: "+String(particles));
screenChangeTime= timeNow + delay;
display.display();
}
}
Server responds:
void loop() {
server.handleClient();
}
1 Answer 1
My guess is, that you're wasting too much time within the drawing-part.
What is the value for delay
? I guess you have a number too low chosen here. And you should really set this new time after you have updated the display by display.display();
.
Your webserver doesn't respond because he's not called often enough inside this code.
-
The purpose of the if statement is to not draw every time, it's also not a blocking function.Tvde1– Tvde12018年07月16日 13:29:00 +00:00Commented Jul 16, 2018 at 13:29
if ((millis() - previousTime) >= screenChangeTime) { previousTime += screenChangeTime; ... }
)screenChangeTime
variable is notunsigned long
(even if I doubt that it isn't) it has problems much sooner. In any case, I know it is not the issue here, and in fact it was a comment, not an answer.