Setting a time limit?


hi
quite new programming , arduino ( 2nd day in!) trying use arduino run small motor inflatables. want put time constraint in if motor has been running x amount of time cuts out. struggling time command? have read guessing has millis function? appreciate help?

thanks

rez

the common way determine passage of time on arduino millis function. returns number of milliseconds since system started. if store value of millis when start motor can calculate how long been running. hope following gives ideas how add desired functionality sketch:

[font=courier new]#define cutout (1000 * 60 * 10)  // cut out in 10 minutes
// number of milliseconds cutout - 1000 ms per second, 60 mins per second, 10 number of minutes

// code start motor here
unsigned long starttime = millis();
//following example code wait button press stop motor - replace code
while( digitalread(buttonpin) == high){ // wait button go low
    if( millis() - starttime > cutout) // check if cutout ms has elapsed since motor started
         break; // exit while loop
}
// code stop motor here[/font]


good luck!


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Setting a time limit?


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