User Tools

Site Tools


en-us_commands:reference:igettime

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en-us_commands:reference:igettime [2026/09/07 23:35] – 바깥 편집 127.0.0.1en-us_commands:reference:igettime [2026/09/14 20:30] (current) – external edit 127.0.0.1
Line 14: Line 14:
  
 ===== Example ===== ===== 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 elapsed time updated by ''Iton(0, …)'' with ''IgetTime(0)'' and print it every 0.5 s. The reading is 0 when input is OFF.
  
 <code cpp> <code cpp>
-const uint8_t START_INPUT = 0; +const uint8_t INPUT_PIN = 0; 
-const uint8_t RESET_INPUT 1; +unsigned long lastPrint 0;
-const uint8_t RUN_OUTPUT = 32;+
  
 void setup() { void setup() {
Line 25: Line 26:
  
 void loop() { 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 inputOn digitalRead(INPUT_PIN== HIGH; 
-  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. +  Iton(0, inputOn3000);  // Update the timer in every loop before reading its state
-  const bool ready = Iton(0, start1000);  // (On Delay Timer) Return true only after the condition remains ON for the set time+  const unsigned long elapsedMs IgetTime(0);  // Read elapsed time in ms from the timer with the same ID
-  const bool stopDelay Itof(1, ready, 500);  // (Off Delay Timer) Return false after a set delay following the condition turning OFF. +  if (millis() - lastPrint >500{ 
-  const bool startPulse = Itpl(2, ready, 200);  // (Pulse Timer) Return true for the set duration from the instant the condition turns ON+    lastPrint millis(); 
-  const bool inspectionWindow = Itmon(3, startPulse, 3000);  // (Monostable TimerOutput a pulse whose duration is not extended by another trigger while running. +    Serial.println(elapsedMs);
-  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"));+
   }   }
 } }
Line 44: Line 38:
 ===== Precautions ===== ===== Precautions =====
  
-  * Timer interrupt callbacks run inside an ISR. For safety, change only flags in the callback and perform actual control processing in ''loop()''+  * Call the timer command repeatedly in ''loop()'' so elapsed time and OFF input are processed
-  * Do not use slow or interrupt-dependent code such as ''delay()'', ''Serial'', I2C or SPI in callbacks+  * Do not share a ''timer_id'' between different timer operations; use a separate ID for each
-  * Normally, call ''ImodbusRTU()'' repeatedly in ''loop()''Call it from a timer interrupt with a sufficient interval only when long ''delay()'' calls or debug output slow down ''loop()''+  * Call the timer with the same ID firstAn ID that has not been created returns 0
-  * Do not use the default ''ItimerSet()'' together with ''tone()'' using Timer2 or ''analogWrite()'' 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+===== Built-in Commands in the Same Category ===== 
-  * Configure only one ''Itimer'' callback per hardware timer. + 
-  * Defining an ISR for the same timer directly in the sketch may conflict with ''Itimer'' operation. +  * [[:en-us_commands:reference:igetstate|IgetState() View detailed description]]
-  * ''ItimerStopAll()'' stops only hardware interrupt timers. It does not reset PLC-style timer states such as ''Iton'', ''Itof'' or ''Itmr''.+
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/igettime.1788791734.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki