Hi there :), I am using an Arduino Uno R3, with an I2C LCD module connected to an LCD.
I want to display a message on my LCD without using a delay. I want to achieve this using the millis() function.
It works fine with delay() but with millis(), the LCD never displays the 2th message in the loop. So, the if-condition is never met. It seems like I am doing something wrong here. I appreciate your aid.
J-M-L:
Think about that for a minute or two interval = millis();
My Serial Monitor shows the interval value being increased by 1000 each time. So every time the loop cycles, the LCD has to wait 1 second longer, until it becomes 50 days long and overflows. So, this isn't the right way.
I disabledinterval = millis();
So, now the problem is still that the if-condition is never met. There is still a problem there.
So once it’s triggered, what should previousTime become?
(There is a good tutorial on how to use millis() pinned at the top of the forum. Suggest you read it )
I appreciate your quick responses. The previousTime should save the value of the currentTime when the value difference becomes greater than the interval.
My purpose is to implement this with a sensor in the future. Certain values have a unique gamemode assigned to them. Now, the problem is that the gamemode String message doesn't update. A solution would be to call gamemodeMessage() again after the message string updates, but that causes screen flicker again and it would defeat my purpose of using the millis() function. I would have to add a delay() again.
Possible solution?
-Switch cases with breaks
Are there more practical ways to solve this problem?
I modified the code to work with sensors. I didn't know you could refresh only a certain part of the LCD. I will have to look into that later. I am happy with this code. I works fine for now :).