Print of delay status

Hi

Is it posible to make a print of how much time there is left on a delay?

Br Kasper

Using a timer library, easy peasy. Using delay() itself? Don’t think so.

-jim lee

Hi
I was useing a delay... can you help me with a example of timer library?

Thanks

You would be better off dropping delay altogether and using millis as demonstrated in the blink without delay example.

Hi

I have one millis in the program allready is it posible to have 2 millis in the same program?

Br Kasper

kaan86:
I have one millis in the program allready is it posible to have 2 millis in the same program?

Yes, unless you've done something silly like using millis to implement your own version of delay.

My millisDelay, timer library provides remaining time. Included in the SafeString library from the library manager.
See the detailed tutorial How to Code Timers and Delays in Arduino

The Blocking Delay example shows the use of ledBlockOnDelay.remaining()

kaan86:
Hi
I was useing a delay… can you help me with a example of timer library?

Thanks

Here ya’ go…

#include <timeObj.h> // including the timer library.

timeObj myTimer(5000.0);   // Creating a 5 second timer object.


// Standard setup routine.
void setup(void) { Serial.begin(9600); }


// And our loop routine.
void loop(void) {

   float timeLeft;

   if (!myTimer.ding()) {                                            // If myTImer has not expired..
      timeLeft = (myTimer.getTime()/1000.0) * myTimer.getFraction(); // Calcualte time left.
      Serial.print("Time left : ");                                  // Show Mrs user.
      Serial.print(timeLeft);
      Serial.println(" Ms");
   } else {                                                          // Else, it HAS expired?!
      Serial.println("All done!");                                   // Tell Mrs user we're done.
      while(1);                                                      // Lock process forever!
   } 
}

You will need to install LC_baseTools from the library manager to run this. As written, his will work for times up to 4,000,000 Ms. If you want longer times, it an easy fix.

-jim lee

@jimLee
Nice collection of tools. A suggestion for the debug class. Add setOutput(Print & out) so the user can debug to SerialUSB or Serial1 also removing that statement should turn off all debug output without the need to remove all the debug statements.
Also you don't really need the malloc, just use out.print(num) directly.

Often a variable ‘elapsedMillis’ is used to calculate that.

For example:

const unsigned long interval = 1000UL;

void loop()
{
  unsigned long currentMillis = millis();
  if( currentMillis - previousMillis >= interval)
  {
    previousMillis = currentMillis;
    ...
  }
  else
  {  
    unsigned long elapsedMillis = currentMillis - previousMillis;
    unsigned long remainingMillis = interval - elapsedMillis;
    ...
  }
}

Do you want to make a stopwatch ? There are a few ways to do that, but none of them are pretty.
When you need more software-millis-timers then every millis-timer needs its own ‘previousMillis’.

drmpf:
@jimLee
Nice collection of tools. A suggestion for the debug class. Add setOutput(Print & out) so the user can debug to SerialUSB or Serial1 also removing that statement should turn off all debug output without the need to remove all the debug statements.
Also you don't really need the malloc, just use out.print(num) directly.

Well thank you!

I find that library to be indispensable. Why we have to go over solving the same bloody problems over and over, I could never understand. It feels like I"m hanging out with a bunch of code reenactors. LC_baseTools was written so I could move on to more interesting projects.

-jim lee

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