en-us_commands:reference:igetstate
This is an old revision of the document!
Table of Contents
IgetState()
IgetState() returns the current output state of the specified timer.
bool IgetState(uint8_t timer_id)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
IgetState(timer_id) | uint8_t timer_id — Timer number. Supports 0 ~ 255 | bool | Returns the current output state of the specified timer. |
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. Read the current output state of Iton(0, …) with IgetState(0) and apply it to P32.
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; Iton(0, inputOn, 1000); // Update the timer in every loop before reading its state. const bool done = IgetState(0); // Read the output state of the timer with the same ID. digitalWrite(OUTPUT_PIN, done ? 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. - Call the timer with the same ID first. An ID that has not been created returns false.
Built-in Commands in the Same Category
en-us_commands/reference/igetstate.1789221299.txt.gz · Last modified: by 127.0.0.1
