Table of Contents

IgetTime()

IgetTime() returns the current elapsed time of the specified timer.

IgetTime command operation flow

unsigned long IgetTime(uint8_t timer_id)

Commands

Command Arguments Return Value Operation
IgetTime(timer_id) uint8_t timer_id — Timer number. Supports 0 ~ 255 unsigned long Returns the current elapsed time of the specified timer.

Example

This example selects MPINO-8A4R(T)-S and uses input P0 and output P32. Call the command on every pass through loop() without blocking it. Read the elapsed time updated by Iton(0, …) with IgetTime(0) and print it every 0.5 s. The reading is 0 when input is OFF.

const uint8_t INPUT_PIN = 0;
unsigned long lastPrint = 0;
 
void setup() {
  Serial.begin(115200);
}
 
void loop() {
  const bool inputOn = digitalRead(INPUT_PIN) == HIGH;
  Iton(0, inputOn, 3000);  // Update the timer in every loop before reading its state.
  const unsigned long elapsedMs = IgetTime(0);  // Read elapsed time in ms from the timer with the same ID.
  if (millis() - lastPrint >= 500) {
    lastPrint = millis();
    Serial.println(elapsedMs);
  }
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List