millis problem..

Hi all

i have call that temp function its reading temperature and humidity to write lcd. but my problem is i want to show values on screen 5 sec (without delay)
if i use delay(5000) its ok but all process waiting same time
what i read forum about millis and i made it but problem is not fixed
where is error ?

thx br

code is more then 9000 chars (full code is #include <Button.h> //https://github.com/JChristensen/Button#include <D - Pastebin.com link)

</>
void temp()

{

lcd.clear();
unsigned long currentMillis= millis();

if (currentMillis - previousMillis >= 5000)
{
previousMillis= currentMillis ;

int chk = DHT11.read(DHT11PIN);
lcd.setCursor(1, 1);
lcd.write(0);
lcd.setCursor(3, 1);
lcd.print((float)DHT11.temperature, 0);
lcd.setCursor(5, 1);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(9, 1);
lcd.write(7);
lcd.setCursor(11, 1);
lcd.print((float)DHT11.humidity*2, 0);
lcd.print("%");
}
}
</>

I see a previousMillis and a previousMillis1 - could you be confusing those two?

DrAzzy:
I see a previousMillis and a previousMillis1 - could you be confusing those two?

its previusMillis i changed to 1 ,2 etc.. for different millis it for test but problem again..

osezer34:
Hi all

i have call that temp function its reading temperature and humidity to write lcd. but my problem is i want to show values on screen 5 sec (without delay)
if i use delay(5000) its ok but all process waiting same time
what i read forum about millis and i made it but problem is not fixed
where is error ?

thx br

Please use code tags when posting code. It is </>, most left formatting icon.

You changed from delay to millis, but it didn't fix the problem.
What you are saying is that all your processes still comes to a 5 seconds halt when updating LCD...?

Gabriel_swe:
Please use code tags when posting code. It is </>, most left formatting icon.

You changed from delay to millis, but it didn't fix the problem.
What you are saying is that all your processes still comes to a 5 seconds halt when updating LCD...?

thx for reply
if i use delay to last line on this function lcd show temperature and humidity for 5 sec but arduino completely freze and serial monitor not woking in that 5 sec

osezer34:
thx for reply
if i use delay to last line on this function lcd show temperature and humidity for 5 sec but arduino completely freze and serial monitor not woking in that 5 sec

Good description of delay symptom, but not an answer to my question.

Millis didn't fix the problem. Do you get the same result with millis?

Gabriel_swe:
Good description of delay symptom, but not an answer to my question.

Millis didn't fix the problem. Do you get the same result with millis?

delay is waiting 5 sec
millis not waiting directly show values and clear lcd to other functions

Ahh, you need the same millis code on other function to prevent it from immediately updating LCD with other information.

You can also use state machine to have LCD cycle between your different functions.

the project is so simple
RTC and temperature with humidity

RTC always on lcd screen but every 5 sec i want to see temperature and humidity on lcd

without delay function

thx

Please edit your opening post and add the code tags as requested before.

Please do not edit your opening post to modify code; it confuses (there does not seem to be a previosuMillis1 anymore).

Please post your complete code. You might have an error in e.g. loop or setup.

sterretje:
Please edit your opening post and add the code tags as requested before.

Please do not edit your opening post to modify code; it confuses (there does not seem to be a previosuMillis1 anymore).

Please post your complete code. You might have an error in e.g. loop or setup.

hi thx for reply
my full code more then 9000 chars and forum not supported it and i upload to code to this link

There are over 1400 lines of code in that program - it's a bit much to expect us to explore all of that to find your problem.

Can you write a short program that illustrates the problem - perhaps by deleting irrelevant chunks of the full program.

Have you studied the use of millis() in Several Things at a Time?

...R

Robin2:
There are over 1400 lines of code in that program - it's a bit much to expect us to explore all of that to find your problem.

Can you write a short program that illustrates the problem - perhaps by deleting irrelevant chunks of the full program.

Have you studied the use of millis() in Several Things at a Time?

...R

thx for reply i explaining here.
from loop function millis is working properly... every 5000ms calling function
the temp function must be write HELLO to lcd but string wait on lcd for a 5000ms too
is i use delay its freezing
thx

void loop()
{
  unsigned long currentMillis = millis(); 
  if (currentMillis - previousMillis >= 5000)
  {
   previousMillis = currentMillis;  // Remember the time
   temp();// function to temp
  }
 }




void temp() 
{
  lcd.clear();
  unsigned long currentMillis= millis();
 
if (currentMillis - previousMillis >= 5000)
  {
       
    previousMillis= currentMillis ; // Remember the time

    Serial.println(previousMillis);
    Serial.println(currentMillis);   
 
  lcd.print("HELLO");
   }
  }

Moderator edit: CODE TAGS - why is this so hard to understand?

You should make currentMillis a global variable and only update it once per loop() so that all the timing is related to the same value.

I don't understand this

the temp function must be write HELLO to lcd but string wait on lcd for a 5000ms too is i use delay its freezing

As written I think your code clears the LCD and then waits 5 seconds before printing HELLO - is that what you want?

If you want it to display the word HELLO for 5 seconds and then clear the screen you need to swap the printing with the clear

...R

Robin2:
You should make currentMillis a global variable and only update it once per loop() so that all the timing is related to the same value.

I don't understand this As written I think your code clears the LCD and then waits 5 seconds before printing HELLO - is that what you want?

If you want it to display the word HELLO for 5 seconds and then clear the screen you need to swap the printing with the clear

...R

hi Robin2

i want to see "HELLO" string on LCD 5 sec
after 5 sec clear lcd and other functions etc...

if i use delay(5000) last line of function its working HELLO string waiting 5 sec but multiprocess not working

  unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= 5000)
 {
   previousMillis = currentMillis;  // Remember the time
   temp();
 }

You 'reset' previousMillis in loop(); next you call temp() and you check if the time has lapsed (which will never be the case). I think the best is to unconditionally call temp() from loop().

void loop()
{
  temp();
  ...
  ...
}

Tuz for reply
Not worked it too

osezer34:
hi Robin2

i want to see "HELLO" string on LCD 5 sec
after 5 sec clear lcd and other functions etc...

Have you tried my suggestion in Reply #13 - if so, what happened?

...R

hi robin

tried your suggestion and not worked too
thx for reply

osezer34:
not worked too

Sorry, but that is no help for diagnosing the problem.

First, post the version of the code incorporating my suggestion.
Then give a detailed explanation of what happened when you tried it.

Have you tried my suggestion of making a short program to illustrate the problem?

...R