IgetTime() returns the current elapsed time of the specified timer.
unsigned long IgetTime(uint8_t timer_id)
| 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. |
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); } }
loop() so elapsed time and OFF input are processed.timer_id between different timer operations; use a separate ID for each.