Control time library.


hi,

i'd ask whether knows library manage times.
for example, write code:

code: [select]

unsigned long previousmilis;
int time = 1000;
setup {previousmilis= millis();}
loop {if(millis() - previousmillis > time) {previousmillis = millis();}}


it'd easier library expresion:

code: [select]

timelibrary mytime;
int time = 1000;
loop {if(mytime.check(time)) {}}


our sketchs less tedious manage.

thanks.

can made 1 of problems such function has function call overhead may or may not affect program flow. millis() not bad, micros story quite different.

the code function this.
code: [select]

boolean checktimeelapsedsincelastcall(unsigned long t)  // shorter name possible ;)
{
  static unsigned long prev = 0;
  unsigned long = millis();
  if (now - prev >= t)
  {
     prev = now;
     return true;
  }
  return false;
}


have fun ;)


Arduino Forum > Using Arduino > Programming Questions > Control time library.


arduino

Comments

Popular posts from this blog

CS5 Adobe Media Encoder: Encode failed because the source duration is nil.

cf_sql_integer vs cf_sql_bigint vs cf_sql_int??

localhost/joomla15/administrator doesnt work - Joomla! Forum - community, help and support