User Tools

Site Tools


en-us_commands:reference:itmr

Differences

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

Link to this comparison view

Next revision
Previous revision
en-us_commands:reference:itmr [2026/09/07 21:52] – 만듦 - 바깥 편집 127.0.0.1en-us_commands:reference:itmr [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. ON time at ''P0'' accumulates. ''P32'' turns on after 3 s; OFF time does not clear the sum. ''P1'' resets it.
  
 <code cpp> <code cpp>
-bool Iton(uint8_t timer_id, bool state, unsigned long delayTime)+const uint8_t RUN_INPUT = 0
-bool Itof(uint8_t timer_id, bool state, unsigned long delayTime)+const uint8_t RESET_INPUT = 1
-bool Itpl(uint8_t timer_id, bool state, unsigned long delayTime); +const uint8_t OUTPUT_PIN = 32; 
-bool Itmon(uint8_t timer_id, bool state, unsigned long delayTime); + 
-bool Itmr(uint8_t timer_idbool stateunsigned long delayTimebool reset = false); +void setup() {} 
-unsigned long IgetTime(uint8_t timer_id); + 
-bool IgetState(uint8_t timer_id);+void loop() { 
 +  const bool run = digitalRead(RUN_INPUT== HIGH
 +  const bool reset = digitalRead(RESET_INPUT== HIGH
 +  const bool elapsed = Itmr(0run3000, reset);  // Accumulate ON time; clear it when reset is true. 
 +  digitalWrite(OUTPUT_PIN, elapsed ? HIGH : LOW); 
 +}
 </code> </code>
  
 ===== 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()''+  * When ''reset'' is true, the accumulated time and done state are cleared. 
-  * 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:iton|Iton() 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:reference:itof|Itof() View detailed description]] 
 +  * [[:en-us_commands:reference:itpl|Itpl() View detailed description]] 
 +  * [[:en-us_commands:reference:itmon|Itmon() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/itmr.1788785568.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki