system
March 21, 2012, 3:00am
1
Is it possible to do a continue in the loop()? For instance, if I wanted to do something every second:
void loop() {
// do all of this normally
if(millis()%1000 != 0) {continue;}
//otherwise
//do
//all
//this
//other
//stuff
}
I know I could reverse it and say if(true){then do all the other code} but I'd much prefer to leave it out of a bracketed section if possible.
Note that I'm not actually checking for something every second, so if the if statement isn't perfect, I don't care.
Just return, loop will be called again a moment later:
if(millis()%1000 != 0)
{
return;
}
system
March 21, 2012, 9:37am
3
Just return, loop will be called again a moment later:
Though it is, in my opinion better to put the stuff you do want executed in the body of an if statement.
For future internet voyagers: the millis() % 1000
code is a bad idea. It's unlikely that you'll consistently test millis() exactly on the dot at a 1000 ms increment. You should instead keep a 'nextReading' time that you continuously reset to 1 second from now, and then test if millis() is greater than that to see if you should do your thing.
jasmino
September 27, 2017, 11:11pm
5
the TimerOne library might be what you're looking for. It allows to call a routine every x milliseconds....
don't know how precise it is, but worth to give it a try !
https://code.google.com/archive/p/arduino-timerone/downloads