en-us_commands:reference:itof
This is an old revision of the document!
Table of Contents
Itof()
Itof() (Off Delay Timer) returns false after a specified time has elapsed since the condition turned OFF.
bool Itof(uint8_t timer_id, bool state, unsigned long delayTime)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
Itof(timer_id, state, delayTime) | uint8_t timer_id — Timer number. Supports 0 ~ 255bool state — Timer input stateunsigned long delayTime — Preset time in ms | bool | (Off Delay Timer) returns false after a specified time has elapsed since the condition turned OFF. |
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. The output stays on for 2 s after the input goes off.
const uint8_t INPUT_PIN = 0; const uint8_t OUTPUT_PIN = 32; void setup() { pinMode(INPUT_PIN, INPUT); pinMode(OUTPUT_PIN, OUTPUT); } void loop() { const bool inputOn = digitalRead(INPUT_PIN) == HIGH; const bool outputOn = Itof(0, inputOn, 2000); // Keep returning true for 2 s after the input turns off. digitalWrite(OUTPUT_PIN, outputOn ? 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.
Built-in Commands in the Same Category
en-us_commands/reference/itof.1789221299.txt.gz · Last modified: by 127.0.0.1
