User Tools

Site Tools


en-us_commands:reference:fifo

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:fifo [2026/09/08 00:53] – 바깥 편집 127.0.0.1en-us_commands:reference:fifo [2026/09/12 23:27] (current) – 바깥 편집 127.0.0.1
Line 14: Line 14:
  
 ===== Example ===== ===== Example =====
 +
 +Send ''i'' twice from Serial Monitor to store 10 and 20. Send ''o'' twice to read 10 and then 20. Send ''r'' to empty the buffer.
  
 <code cpp> <code cpp>
-uint16_t fifoValue 0+uint16_t nextValue 10
-uint16_t filoValue = 0; +uint16_t removedValue = 0;
-uint16_t sequence = 0;+
  
 void setup() { void setup() {
   Serial.begin(115200);   Serial.begin(115200);
 +  Serial.println(F("i: store, o: take, r: reset"));
 } }
  
 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 key = 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 key == 'i'; 
 +  const bool take = key == 'o'; 
 +  const bool reset = key == 'r'; 
 +  if (!store && !take && !reset) return;
  
-  if (store) ++sequence; +  const bool ok = FIFO(0, store, takenextValueremovedValue4, reset);  // Store or retrieve a value on the rising edge of IN or OUT
-  const bool fifoOk = FIFO(0, store, releasesequencefifoValue16, reset);  // Output the first stored 16-bit data first+  FIFO(0, falsefalse0removedValue4);  // Return IN and OUT to OFF so the next key creates a new rising edge. 
-  const bool filoOk = FILO(0, storereleasesequencefiloValue16, reset);  // Output the last stored 16-bit data first+ 
-  if (release && fifoOk && filoOk) { +  if (reset) { 
-    Serial.print(F("oldest=")); Serial.print(fifoValue); +    nextValue = 10; 
-    Serial.print(F(", newest=")); Serial.println(filoValue);+    Serial.println(F("buffer cleared")); 
 +  } else if (!ok) { 
 +    Serial.println(F("buffer full or empty")); 
 +  } else if (store) { 
 +    Serial.print(F("stored: ")); 
 +    Serial.println(nextValue); 
 +    nextValue +10; 
 +  } else { 
 +    Serial.print(F("taken: ")); 
 +    Serial.println(removedValue);
   }   }
 } }
 </code> </code>
 +
 +Pushing to a full buffer or popping from an empty one fails.
  
 ===== Precautions ===== ===== Precautions =====
en-us_commands/reference/fifo.1788796396.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki