Measuring time in arduino

Hello guys,

sorry, if this is an old subject that has been discussed before, but I cannot find the solution on google... have tried millis() function, which works perfectly. However, I wanted to get around with a simple class or library..., such as StopWatch (Arduino Playground - StopWatchClass) or Chrono (GitHub - SofaPirate/Chrono: Chrono library for Arduino and Wiring), but I cannot get around either >:(

Have any of you recent experiences with those two, are they still in stable operation, have tried different examples of Chrono e.g., but it does not work... For instance, the simple example like the one below does not compile :confused:

// INCLUDE CHRONO LIBRARY
// Download : https://github.com/SofaPirate/Chrono/archive/master.zip
#include <Chrono.h>

// Instanciate a Chrono object.
Chrono myChrono; 

void setup() {
  // Start the chronometer on setup.
  myChrono.start();
}

void loop() {
  // Check whether the chronometer has reached 1000 time units.
  if (myChrono.hasPassed(1000)) {
    // Do something here...
    // Restart the chronometer.
    myChrono.restart();
  }
}

Error:
sketch_may15b:10: error: 'class Chrono' has no member named 'start'
myChrono.start();
^
Multiple libraries were found for "Chrono.h"
Used: /Users/imac27/Documents/Arduino/libraries/Chrono
Not used: /Users/imac27/Documents/Arduino/libraries/Chrono-master
exit status 1
'class Chrono' has no member named 'start'

Any ideas what I am doing wrong?

MU

why not just use the Time library included in the IDE?

Where did you get the 2 Chrono libraries that you have installed ?
Is the program that you posted one of the examples installed with the libraries ?

Chrono is available here: GitHub - SofaPirate/Chrono: Chrono library for Arduino and Wiring
YES, see basic example at the above link...

BulldogLowell:
why not just use the Time library included in the IDE?

I did and it works, however, I have considered, if there is easier way to do this...

mu234:
I did and it works, however, I have considered, if there is easier way to do this...

To do what? It is not clear from your initial post what problem you are trying to solve.

mu234:
I did and it works, however, I have considered, if there is easier way to do this...

easier than "Problem Solved"?

what does Time not do for you?

I use FlexiTimer2 Library - simple to set up, uses an interrupt callback, where I increment a counter. You can set the interrupt to be called every second or whatever you want.

mu234:
Chrono is available here: GitHub - SofaPirate/Chrono: Chrono library for Arduino and Wiring
YES, see basic example at the above link...

I could not see a "basic example" among the examples there. What exactly is the name of the program ?

Multiple libraries were found for "Chrono.h"
Used: /Users/imac27/Documents/Arduino/libraries/Chrono

What's this?
-- A wild guess: an older version of the library that did not have start() (if not something completely different).

Not used: /Users/imac27/Documents/Arduino/libraries/Chrono-master
And this is probably what you are trying to use.

Get rid of the upper library.

UKHeliBob:
I could not see a "basic example" among the examples there. What exactly is the name of the program ?

It's on the front page, just scroll down a little.

Hello to all!

Sorry for my late reply, but I do not have computer on me :slight_smile:

I have removed the master Chrono version... I guess it should work now, however, I have in the mean time implemented what I need with the millis()... so far so good, the problem is that if the program is running for few days it starts behaving strange... eventually it stops working. I guess the problem is with millis(), because after few days it becomes unstable...

Is there a way to reset millis() and start counting again, rather than counting all the time?

This could be a solution?

Hence I have started to use the Chrono... if necessary I will get back to it and eventually use the library :slight_smile:

BEST.

Is there a way to reset millis() and start counting again, rather than counting all the time?

No unless you want to reset the Arduino.

However, why would you need to do it anyway ? When you want to start timing save the current value of millis(). Then, when you want to know how much time has passed compare the start time with the current value of millis().

I guess the problem is with millis(),

Guess again.

biggles:
I use FlexiTimer2 Library - simple to set up, uses an interrupt callback, where I increment a counter. You can set the interrupt to be called every second or whatever you want.

thanks for the input, will have it a go at some time!

BEST.