User Tools

Site Tools


en-us_commands:reference:ibounceon

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
en-us_commands:reference:ibounceon [2026/09/07 23:35] – 바깥 편집 127.0.0.1en-us_commands:reference:ibounceon [2026/09/08 00:53] (current) – 바깥 편집 127.0.0.1
Line 16: Line 16:
  
 <code cpp> <code cpp>
 +const uint8_t START_INPUT = 0;
 +const uint8_t STOP_INPUT = 1;
 +const uint8_t RUN_OUTPUT = 32;
 +
 void setup() { void setup() {
-  pinMode(0, INPUT);+  Serial.begin(115200);
 } }
  
 void loop() { void loop() {
-  bool stableInput = Ibounce(0, 20);  // Applies a debounce time in both ON and OFF directions of the input. +  const bool start = IbounceOn(START_INPUT, 100);  // Apply the time filter only when the input changes from OFF to ON. 
-  bool onDelayed = IbounceOn(1, 100);  // Apply the time filter only when the input changes from OFF to ON. +  const bool stop = IbounceOff(STOP_INPUT, 100);  // Apply the time filter only when the input changes from ON to OFF. 
-  bool offDelayed = IbounceOff(2, 100);  // Apply the time filter only when the input changes from ON to OFF.+  const bool run = start && !stop; 
 +  digitalWrite(RUN_OUTPUT, run ? HIGH : LOW); 
 + 
 +  static bool previousRun = false; 
 +  if (run != previousRun) { 
 +    previousRun = run; 
 +    Serial.println(run ? F("motor RUN") : F("motor STOP")); 
 +  }
 } }
 </code> </code>
Line 30: Line 41:
  
 The ''Ibounce'' functions retain state, so keep calling them in ''loop()''. Specify the actual pin or logical channel for your product. The ''Ibounce'' functions retain state, so keep calling them in ''loop()''. Specify the actual pin or logical channel for your product.
 +
 +===== Built-in Commands in the Same Category =====
 +
 +  * [[:en-us_commands:reference:idigitalread|IdigitalRead() View detailed description]]
 +  * [[:en-us_commands:ibounce|Ibounce() View detailed description]]
 +  * [[:en-us_commands:reference:ibounceoff|IbounceOff() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/ibounceon.1788791733.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki