User Tools

Site Tools


en-us_commands:reference:igettime

This is an old revision of the document!


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() {
  pinMode(INPUT_PIN, INPUT);
  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

  • Call the timer command repeatedly in loop() so elapsed time and OFF input are processed.
  • Do not share a timer_id between different timer operations; use a separate ID for each.
  • Call the timer with the same ID first. An ID that has not been created returns 0.

Built-in Commands in the Same Category

en-us_commands/reference/igettime.1789221299.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki