I want to display temperature from various sensors while running other code.
If i do somthing like blink without delay it will constantly display for 1 minute them wait a minute.
How do i make the serial print happen only once each minute?
Thanks
I want to display temperature from various sensors while running other code.
If i do somthing like blink without delay it will constantly display for 1 minute them wait a minute.
How do i make the serial print happen only once each minute?
Thanks
Blink....without....delay.
If i do somthing like blink without delay it will constantly display for 1 minute them wait a minute.
Not if you do it right. The philosophy show how to do something when it is time, not how to do one thing or the other at defined intervals.
easterly81:
I want to display temperature from various sensors while running other code.If i do somthing like blink without delay it will constantly display for 1 minute them wait a minute.
How do i make the serial print happen only once each minute?
What the others are telling you is that the example needs to be understood, not that it needs to be blindly copied.
Lets look at what you need to do, using the principles found in Blink Without Delay
declare an unsigned long variable called start_time
declare an unsigned long variable called duration
setup
set up pins,
set up Serial
Save current millis() in start_time
end of setup
loop
if the current millis() - start_time is >= duration
do something (this could include reading temperature and printing it)
Save current millis() in start_time (starts the timing all over again)
end of the if
do any other stuff you want to do
end of the loop (goes back to loop)
lar3ry:
easterly81:
I want to display temperature from various sensors while running other code.If i do somthing like blink without delay it will constantly display for 1 minute them wait a minute.
How do i make the serial print happen only once each minute?
What the others are telling you is that the example needs to be understood, not that it needs to be blindly copied.
Lets look at what you need to do, using the principles found in Blink Without Delaydeclare an unsigned long variable called start_time
declare an unsigned long variable called duration
setup
set up pins,
set up Serial
Save current millis() in start_time
end of setup
loop
if the current millis() - start_time is >= duration
do something (this could include reading temperature and printing it)
Save current millis() in start_time (starts the timing all over again)
end of the if
do any other stuff you want to do
end of the loop (goes back to loop)
thanks for the not so smart %#s reply
the = is what i believe is was missing right before the interval
easterly81:
the = is what i believe is was missing right before the interval
Of course! How could anybody have missed that? What "="?
Perhaps it was your detailed and specific questions that threw me?
YES just tried it and it works!
Thanks Lar3ry
today is actually my birthday the "==" was the B-day gift ever lol
long previousMillis = 0;
long interval = 60000;
void setup() {
Serial.begin(9600);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis == interval) {
Serial.println("Test");
previousMillis = currentMillis;
}
}
if(currentMillis - previousMillis == interval) {
This is an error waiting to happen. Maybe not in this code on this Arduino but keep using that and you'll see.
What error? Well, what happens if the exact milli where that is true is missed for any reason? That error.
So i need a rang not exact millis?
No, you just need '>='
And to help you with future coding, maybe check out all the sections in the link below that have Operator in the name.
There's patterns to them as well as differences but they're all very useful.