I have a sketch that displays the time and temp on a 1602 lcd and it works to a point. I have no delays in the sketch but while watching the seconds tick away, I notice that there is a delay every 11 to 14 seconds or so. It seems to be losing a second each time. If you could, please tell me what could be wrong.
I'm curious why you use the value of ap, and THEN assign a value to it.
The temperature sensors take a while to read - about 3/4 of a second. Sometimes, a reading will complete within a one second window. Other times, it won't. When it doesn't the seconds value will jump.
PaulS:
I'm curious why you use the value of ap, and THEN assign a value to it.
The temperature sensors take a while to read - about 3/4 of a second. Sometimes, a reading will complete within a one second window. Other times, it won't. When it doesn't the seconds value will jump.
I used that value as it was already in the code I found online. I do not know why they used it. I just left it there because the clock was working. I added in the temperature part on my own. I am still learning this stuff.
bigone5500:
I have a sketch that displays the time and temp on a 1602 lcd and it works to a point. I have no delays in the sketch but while watching the seconds tick away, I notice that there is a delay every 11 to 14 seconds
I think the problem is entirely within the clock, and has nothing to do with how long the sensor takes to do its job. The way you have it, the sensor will take 750ms to do its job - always. Furthermore, the sensor does not hold things up until it has done its job, as implied, it simply sends an error code if you haven't allowed it the time to do its job. The error is -85C - a figure you don't mention, and I therefore assume you don't have a problem in the temperature department. I think you would mention it if you saw it because you would probably be getting it all the time.
You might get less grief in the clock department by going here
I mention this because it is the first clock programme I found that made sense and actually worked. You can get smarty farty with clock loops but the simplest way to go is do what you don't - put in a delay. You can tune the delay if you need to, but I suspect pretty well anything will work better than what you have.
You may already be aware that you can change the time the DS18B20 takes to return a reading by changing its resolution. You appear to currently be in 12 bit by default, and that should be fine anyway.