Skip to content

Instantly share code, notes, and snippets.

@rat
Last active December 29, 2015 06:09
Show Gist options
  • Save rat/7626940 to your computer and use it in GitHub Desktop.
Save rat/7626940 to your computer and use it in GitHub Desktop.
// Defining the constants present in the code
unsigned long cycle = 300000;
unsigned long lastMillis = 0;
void setup(){}
void loop(){
if(cycleCheck(&lastMillis, cycle)) {
// faz o que você quer.
}
}
// function for multitasking
// http://arduino.cc/forum/index.php/topic,5686.msg44073.html
boolean cycleCheck(unsigned long *lastMillis, unsigned long cycle) {
unsigned long currentMillis = millis();
if(currentMillis - *lastMillis >= cycle) {
*lastMillis = currentMillis;
return true;
}
else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment