User Tools

Site Tools


en-us_commands:reference:ialt

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:ialt [2026/09/07 21:52] – 만듦 - 바깥 편집 127.0.0.1en-us_commands:reference:ialt [2026/10/25 08:40] (current) – external edit 127.0.0.1
Line 16: Line 16:
  
 <code cpp> <code cpp>
-bool lampState = false;+const uint8_t COMMAND_INPUT = 0; 
 +const uint8_t MOTOR_OUTPUT = 32; 
 + 
 +void setup() { 
 +  Serial.begin(115200); 
 +}
  
 void loop() { void loop() {
-  Ialt(digitalRead(0), lampState); +  const bool input = IdigitalRead(COMMAND_INPUT, 5);  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state. 
-  digitalWrite(32, lampState);+  const bool started = Iup(0, input);  // Return true only at the instant the input changes from OFF to ON. 
 +  const bool stopped = Idown(0, input);  // Return true only at the instant the input changes from ON to OFF. 
 +  static bool run = false; 
 +  Ialt(started, run);  // Toggle the specified state ON/OFF at each rising input edge. 
 + 
 +  digitalWrite(MOTOR_OUTPUT, run ? HIGH : LOW); 
 +  if (started) Serial.println(F("motor started")); 
 +  if (stopped) Serial.println(F("command released"));
 } }
 </code> </code>
Line 26: Line 38:
 ===== Precautions ===== ===== Precautions =====
  
-Using the same ''id'' for different signals may mix their previous states. Do not set the minimum and maximum of the ''Iscale'' input range to the same value.+''Ialt()'' tracks the previous input by the address of ''state_var''. Use a separate ''bool'' state variable that persists between calls, as in the example. 
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/ialt.1788785565.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki