I'm fairly new to Arduino and am trying to figure out the best way to implement something. I am using Arduino IoT cloud which mentions that ideally there shouldn't be delays since it can get in the way of the connection process to the IoT cloud.
I have a program where I determine how much beer is left in a keg. I do this with an accelerometer attached to the tap handle. When the accelerometer reaches a certain angle, a while loop beings while the beer is pouring, and I then exit the loop, do some math, and show the results on an OLED display (e.g. a number showing '40%' signifying 40% of the keg remains). My concern is that this number may sit on the OLED screen for days+ at a time and will eventually lead to OLED burn-in. Maybe this isn't a big deal, especially when the OLED itself is cheap, but I'm looking to get around it and learn at the same time.
So the idea is I need to be able to read from the accelerometer nearly instantly as soon as the tap handle reaches a certain angle. At the same time though, I would like to display different images/numbers on the screen to prevent burn-in. For instance, if the keg is 50% full, I can cycle between showing the "50%" as well as a picture of a keg that is half full alongside other things. However, if I do something like below, if the tap handle starts pouring in the middle of the 5 second delay, the program is halted and the amount calculated being poured will be incorrect.
Is there any way to get around this? I can post my entire project if it is helpful. I have read into the millis function but I don't know if that helps me because it seem this only counts time from the start of the program. Any thoughts on what to use to program this properly?
if (kegRemaining == 50){
display.clearDisplay();
display.setTextSize(4);
display.setTextColor(WHITE);
display.setCursor(23, 25);
display.print(kegRemaining);
display.print("%");
display.display();
delay(5000);
display.clearDisplay();
display.drawBitmap(0, 16, epd_bitmap_keg, 128, 64, 1);
display.display();
delay(5000);