User Tools

Site Tools


en-us_commands:reference:itmr

This is an old revision of the document!


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() {
  pinMode(RUN_INPUT, INPUT);
  pinMode(RESET_INPUT, INPUT);
  pinMode(OUTPUT_PIN, OUTPUT);
}
 
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/itmr.1789221299.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki