User Tools

Site Tools


en-us_commands:reference:filo

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:filo [2026/09/07 23:35] – 바깥 편집 127.0.0.1en-us_commands:reference:filo [2026/09/14 20:30] (current) – external edit 127.0.0.1
Line 14: Line 14:
  
 ===== Example ===== ===== Example =====
 +
 +Send ''a'' in Serial Monitor to store the next number, ''p'' to retrieve the most recently stored number, or ''c'' to clear the buffer. Send one character at a time to observe the behavior.
  
 <code cpp> <code cpp>
-uint16_t fifoValue = 0; +uint16_t nextNumber = 0; 
-uint16_t filoValue = 0; +uint16_t lastNumber = 0;
-uint16_t sequence = 0;+
  
 void setup() { void setup() {
Line 25: Line 26:
  
 void loop() { void loop() {
-  const bool store = Iup(0, IdigitalRead(0, 5));  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state. / Return true only at the instant the input changes from OFF to ON+  if (!Serial.available()) return; 
-  const bool release Iup(1, IdigitalRead(1, 5));  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state. / Return true only at the instant the input changes from OFF to ON. +  const char action = Serial.read(); 
-  const bool reset IdigitalRead(2, 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 store action == 'a'; 
 +  const bool retrieve = action == 'p'; 
 +  const bool clearBuffer action == 'c'; 
 +  if (store) ++nextNumber;
  
-  if (store) ++sequence; +  const bool ok FILO(0, store, retrievenextNumberlastNumber, 16, clearBuffer);  // Store a number; on a pop signal, retrieve the last stored number
-  const bool fifoOk FIFO(0, store, releasesequencefifoValue, 16, reset);  // Output the first stored 16-bit data first+  FILO(0, falsefalsenextNumberlastNumber, 16, false);  // Return both inputs to LOW so the next character creates a new rising edge
-  const bool filoOk = FILO(0, storereleasesequencefiloValue, 16, reset);  // Output the last stored 16-bit data first+  if (retrieve && ok) Serial.println(lastNumber); 
-  if (release && fifoOk && filoOk+  if (retrieve && !ok) Serial.println(F("Buffer empty"));
-    Serial.print(F("oldest=")); Serial.print(fifoValue)+
-    Serial.print(F(", newest=")); Serial.println(filoValue); +
-  }+
 } }
 </code> </code>
Line 42: Line 43:
  
 ''IN'', ''OUT'', ''CU'' and ''CD'' act on rising edges. Use a unique ''id'' for each counter or buffer, and keep ''size'' to the required minimum. ''IN'', ''OUT'', ''CU'' and ''CD'' act on rising edges. Use a unique ''id'' for each counter or buffer, and keep ''size'' to the required minimum.
 +
 +===== Built-in Commands in the Same Category =====
 +
 +  * [[:en-us_commands:reference:fifo|FIFO() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/filo.1788791733.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki