Exit function after specified time


hi,

im not sure if asked before, wondering if break function if function doesn't execute in 6 seconds.

basically function running calculate time takes magnet pass once on reed switch:

code: [select]
void tripuino::rech(unsigned long *timestart, unsigned long *timeend){
   while (digitalread(3) == high){
   }
   *timestart = millis();
   while (digitalread(3) == low){
   }
   while (digitalread(3) == high){
   }
   *timeend = millis();
}

i want function stop executing if takes longer 6 seconds indicate speed 0 in rest of code. need use interrupt or there way of achieving goal?

thanks in advance

you should move timestart declaration before first while loop. then, in each while loop, check condition , check (millis()) minus start time less 6 seconds.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Exit function after specified time


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums