en-us_commands:reference:igettime
This is an old revision of the document!
Table of Contents
IgetTime()
IgetTime() returns the current elapsed time of the specified timer.
unsigned long IgetTime(uint8_t timer_id)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
IgetTime(timer_id) | uint8_t timer_id — Timer number. Supports 0 ~ 255 | unsigned long | Returns the current elapsed time of the specified timer. |
Example
const uint8_t START_INPUT = 0; const uint8_t RESET_INPUT = 1; const uint8_t RUN_OUTPUT = 32; void setup() { Serial.begin(115200); } void loop() { const bool start = IdigitalRead(START_INPUT, 5); // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state. const bool reset = IdigitalRead(RESET_INPUT, 5); // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state. const bool ready = Iton(0, start, 1000); // (On Delay Timer) Return true only after the condition remains ON for the set time. const bool stopDelay = Itof(1, ready, 500); // (Off Delay Timer) Return false after a set delay following the condition turning OFF. const bool startPulse = Itpl(2, ready, 200); // (Pulse Timer) Return true for the set duration from the instant the condition turns ON. const bool inspectionWindow = Itmon(3, startPulse, 3000); // (Monostable Timer) Output a pulse whose duration is not extended by another trigger while running. const bool batchDone = Itmr(4, ready, 10000, reset); // (Retentive Timer) Accumulate the time the condition is ON; clear it with the Reset input. const unsigned long elapsed = IgetTime(4); // Return the specified timer's current elapsed time. const bool savedDone = IgetState(4); // Return the specified timer's current output state. digitalWrite(RUN_OUTPUT, stopDelay && !batchDone ? HIGH : LOW); if (inspectionWindow && elapsed % 1000 < 20) { Serial.println(savedDone ? F("batch complete") : F("batch running")); } }
Precautions
- Timer interrupt callbacks run inside an ISR. For safety, change only flags in the callback and perform actual control processing in
loop(). - Do not use slow or interrupt-dependent code such as
delay(),Serial, I2C or SPI in callbacks. - Normally, call
ImodbusRTU()repeatedly inloop(). Call it from a timer interrupt with a sufficient interval only when longdelay()calls or debug output slow downloop(). - Do not use the default
ItimerSet()together withtone()using Timer2 oranalogWrite()on Timer2 PWM pins. - Explicitly using Timer1, Timer3, Timer4 or Timer5 may conflict with PWM, analog output or high-speed counter functions using that timer.
- Configure only one
Itimercallback per hardware timer. - Defining an ISR for the same timer directly in the sketch may conflict with
Itimeroperation. ItimerStopAll()stops only hardware interrupt timers. It does not reset PLC-style timer states such asIton,ItoforItmr.
en-us_commands/reference/igettime.1788791734.txt.gz · Last modified: by 127.0.0.1
