Go Down

Topic: loop for a certain period of time (Read 3223 times) previous topic - next topic

award982

Hey people,
I need some help with my multiplexer, i want to ask is there a way to make a loop to do something for a specified amount of time? I suppose with counters it is also possible but isn't there a way to do like

while(10 seconds not passed)
something;

i suppose i can use a timer that would count an integer to 10 each second +1, and use a loop like

while(integer that is used by the timer <= 10)
something;

Possible? or am i asking something stupid?

PaulS

Code: [Select]
unsigned long startTime = millis();
unsigned long interval = 10000UL; // 10 seconds

while(millis() - startTime < interval)
{
 // Do whatever
}
The art of getting good answers lies in asking good questions.

award982


Go Up