Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,
It seems that the millis() counter is incrementing when it shouldn't.
It's displaying 5831 for the number of seconds when at most it has been 31, there is a reasonably accurate temp monitor. I'm guessing the 58 could be due to the LCD driver getting in the way, but that If() turns the Green light on, resets the seconds. But it still holds the value on the screen. Arduino IDE not a fan of!

C++
if (temperature < Min_Temp)
   {
     Seconds = 0;
     digitalWrite(Green_LED, HIGH);
     digitalWrite(Blue_LED, LOW);
     digitalWrite(Red_LED,LOW);
   }else if(temperature >Min_Temp && temperature < Max_Temp)
   {
     digitalWrite(Green_LED,LOW);
     digitalWrite(Blue_LED,HIGH);
     digitalWrite(Red_LED,LOW);
     microsA = millis();
     Seconds = (microsA /1000);

   }else if(temperature > Max_Temp)
   {
     Seconds = 0;
     digitalWrite(Green_LED,LOW);
     digitalWrite(Blue_LED,LOW);
     digitalWrite(Red_LED,HIGH);
   }
 lcd.setCursor(0, 1);
 lcd.print("Time:");
 lcd.setCursor(5,1);
 lcd.print(Seconds);
 delay(500);

But it still holds the value on the screen. The value is sent out via the I2C commands it does the temperature properly. Could there be an issue with LCD commands printing commands

What I have tried:

Setting Seconds to equal 0 , it must go into that bit of the if() as the green led turns on.
Posted
Updated 20-Apr-23 2:10am
v2
Comments
0x01AA 22-Apr-23 6:34am    
Think about what happens when temperature == Min_Temp and also the case when temperature == Max_Temp ;)

This should do the job:

if (temperature < Min_Temp)
{
....
}else if(temperature < Max_Temp)
{
....
}else
{
....
}
glennPattonWork3 22-Apr-23 7:41am    
Bit bounds checking not a bad idea...
0x01AA 22-Apr-23 11:10am    
No idea what you mean with 'Bit bounds checking'. The code I suggested is simply: simple and logical and correct ;)

The code you provided shows a lack of knowledge on boolean math ;)
glennPattonWork3 22-Apr-23 11:49am    
Okay, firstly doing a straight boolean check shows you have little idea of what I was trying to do, temperature is a floating point number, the simple boolean example you give will work for less than or greater than, but not a value inbetween which from your example would be handled by the else. I would suggest looking carefully before giving a scathing reply. Also by your lack of knowledge of Bit Boundary I would bet very careful giving that sort of reply.
0x01AA 22-Apr-23 12:26pm    
Sorry, I'm very sure I'm right and you are _very_ wrong.
And yes, I claim you don't understand the basics of logical comparisons!

[Edit]
And you even don't get that it is better to reply to a comment using the 'reply button' of a comment

Hi All,

Wasn't using the counter correctly, wasn't using
<
C++
startMillis = 0;
blah, blah, blah;
Timer = TimeValue - startMillis;
print (Timer);

Always happens ask a question think of the Answer! Sorry!!
 
Share this answer
 
Comments
Patrice T 20-Apr-23 8:48am    
Accept your solution, it tells every one that the question is solved.
0x01AA 22-Apr-23 12:35pm    
I don't understand why you support such bull sh*t
Patrice T 22-Apr-23 14:14pm    
Idon't support anything.
Obviously OP is satisfied with its own solution, so accepting it will close the question0
Pete O'Hanlon 23-Apr-23 15:49pm    
You're coming across as very hostile in this post. You could simply have moved on, but you've chosen to be angry and make this personal.
glennPattonWork3 23-Apr-23 19:11pm    
Okay, I had solved it myself and moved on, marked it as solved and then some genius comes up with a solution which wouldn't solve the issue and then tells me I don't understand the problem and I can't use the correct reply method (when I did!). This is the sort of rubbish that stated on Stack Overflow, we don't want CP over run by the same attitude.
Use Serial.Print(Seconds) and check the output using the serial monitor. It is a cheap & quick way to gain some insight.
 
Share this answer
 
Comments
glennPattonWork3 22-Apr-23 11:53am    
I would normally but the Prehistoric rig (Approve for Window 2.0!) I was using object to that.
That bit is working now, Now to play with a realtime clock!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900