Chrono Literals

std::chrono, chrono, std.chrono

Since 1.5.0:

A number of APIs have been modified to support chrono literals. For example, instead of having to use 2000 for 2 seconds in the delay(), you can use 2s for 2 seconds.

// EXAMPLE
SerialLogHandler logHandler;

void setup() {
}

void loop() {
    Log.info("testing");
    delay(2s);
}

The available units are:

Literal Unit
us microseconds
ms milliseconds
s seconds
min minutes
h hours

Individual APIs may have minimum unit limits. For example, delay() has a minimum unit of milliseconds, so you cannot specify a value in microseconds (us). If you attempt to do this, you will get a compile-time error:

../wiring/inc/spark_wiring_ticks.h:47:20: note:   no known conversion for argument 1 from 'std::chrono::microseconds {aka std::chrono::duration<long long int, std::ratio<1ll, 1000000ll> >}' to 'std::chrono::milliseconds {aka std::chrono::duration<long long int, std::ratio<1ll, 1000ll> >}'

Some places where you can use them:

  • delay()
  • delayMicroseconds()
  • Particle.pubishVitals()
  • Particle.keepAlive()
  • System.sleep()
  • Timer::changePeriod()
  • Timer::changePeriodFromISR()
  • ApplicationWatchdog
  • Cellular.setListenTimeout()
  • Ethernet.setListenTimeout()
  • WiFi.setListenTimeout()