Loop while for a certain time only works once

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?

Please post a complete sketch that illustrates the problem

what is the mess?
Why do you substract milliseconds ( startTime) from microseconds (micros)?

millis() and micros() mean different things.

startTime = millis(); <<<<<<<<<<<<<<<<<<<< MILLIS()
  float time_millis = time * 1000.0;
      while ((micros() - startTime) < time_millis){ <<<<<micros()?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

}

why not

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;
    }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.