Hi Im working on a project where I need to do whatever in a certain time that is pre selected by the user, this only works for the first time and then always skips the loop:
startTime = millis();
float time_millis = time * 1000.0;
while ((millis() - startTime) < time_millis){
}
Inside the loop I use the function micros() maybe is the problem. Any advice?
unsigned Long msecPeriod = 0;
unsigned Long msecLst;
unsigned long msec = millis();
if (0 != msecPeriod && msec - msecLst >= msecPeriod) {
msecLst = msec; // reset or msecPeriod = 0;
// do something
}
...
if (some user input) {
msecPeriod = some user value
msecLst = msec;
}