How fast is a (void) loop?
-
Hi,
I would like to include a Temp Sensor into a Relay with Button Actuator.
Of course, sending the Relay to sleep (like it is in the Temp Sketch) is not the most useful thing, So I thought I just put a counter into the loop and the temp reading is sent every x time and then the counter is set to 0. So my question would be, how long it takes to run a loop? Aproximately! I would be happy if the Temp is transmitted every 5-10 Minutes.
Many Thanks
Petz
-
@Meister_Petz Hi, the best way is to take time as reference. Take a look at the sketch http://www.mysensors.org/build/display. This shows a flexible way of doing things "once in a while"
-
Hi,
it would also be possible to just use a Timer and Interrupt. This might be not as flexible as using the time as reference but you dont have to deal with getting the RTC from the gateway etc.
For an example have a look at:
http://playground.arduino.cc/Deutsch/HalloWeltMitInterruptUndTimerlibraryregards
Dirk_H
-
@Meister_Petz I use millis() for this exact thing and it has been working great for me for months.
Here is an example of what I do:unsigned long DHTPreviousMillis = 0; // last time update. long DHTDelay = 120000; // interval at which to do something (milliseconds) //Delay temperature and humidity for the length of time of DHTDelay without stopping the whole program unsigned long DHTCurrentMillis = millis(); if(DHTCurrentMillis - DHTPreviousMillis > DHTDelay) { DHTPreviousMillis = DHTCurrentMillis; //do something here }
See http://stackoverflow.com/questions/10773425/performing-a-function-after-x-time for more details on Millis delay
Hope that helps.