====== Itmr() ====== ''Itmr()'' (Retentive Timer) accumulates the time the condition is ON and clears it with the Reset input. {{:en-us_commands:reference:itmr.svg?900|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 ===== * 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. * When ''reset'' is true, the accumulated time and done state are cleared. ===== Built-in Commands in the Same Category ===== * [[:en-us_commands:reference:iton|Iton() View detailed description]] * [[:en-us_commands:reference:itof|Itof() View detailed description]] * [[:en-us_commands:reference:itpl|Itpl() View detailed description]] * [[:en-us_commands:reference:itmon|Itmon() View detailed description]] [[:en-us_commands:builtin|← Built-in Command List]]