en-us_commands:reference:itmr
This is an old revision of the document!
Table of Contents
Itmr()
Itmr() (Retentive Timer) accumulates the time the condition is ON and clears it with the Reset input.
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 ~ 255bool state — Timer input stateunsigned long delayTime — Preset time in msbool 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_idbetween different timer operations; use a separate ID for each. - When
resetis 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
