Table of Contents

Itmr()

Itmr() (Retentive Timer) accumulates the time the condition is ON and clears it with the Reset input.

Itmr command operation flow

bool Itmr(uint8_t timer_id, bool state, unsigned long delayTime, bool reset = false)

Commands

Command Arguments Return Value Operation
Itmr(timer_id, state, delayTime, reset) uint8_t timer_id — Timer number. Supports 0 ~ 255
bool state — Timer input state
unsigned long delayTime — Preset time in ms
bool reset = false — Clear the Itmr accumulated value
bool (Retentive Timer) accumulates the time the condition is ON and clears it with the Reset input.

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. ON time at P0 accumulates. P32 turns on after 3 s; OFF time does not clear the sum. P1 resets it.

const uint8_t RUN_INPUT = 0;
const uint8_t RESET_INPUT = 1;
const uint8_t OUTPUT_PIN = 32;
 
void setup() {}
 
void loop() {
  const bool run = digitalRead(RUN_INPUT) == HIGH;
  const bool reset = digitalRead(RESET_INPUT) == HIGH;
  const bool elapsed = Itmr(0, run, 3000, reset);  // Accumulate ON time; clear it when reset is true.
  digitalWrite(OUTPUT_PIN, elapsed ? HIGH : LOW);
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List