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

Next revision
Previous revision
en-us_commands:reference:fifo [2026/09/07 21:52] – 만듦 - 바깥 편집 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 fifoOut+uint16_t nextValue = 10
-FIFO(0, digitalRead(0)digitalRead(1)D[0]fifoOut, 10);+uint16_t removedValue = 0; 
 + 
 +void setup() { 
 +  Serial.begin(115200); 
 +  Serial.println(F("i: store, o: take, r: reset")); 
 +
 + 
 +void loop() { 
 +  if (!Serial.available()) return; 
 +  const char key = Serial.read(); 
 +  const bool store = key == 'i'; 
 +  const bool take = key == 'o'; 
 +  const bool reset = key == 'r'; 
 +  if (!store && !take && !reset) return; 
 + 
 +  const bool ok = FIFO(0, store, take, nextValue, removedValue, 4, reset);  // Store or retrieve a value on the rising edge of IN or OUT. 
 +  FIFO(0, false, false, 0, removedValue4);  // Return IN and OUT to OFF so the next key creates a new rising edge. 
 + 
 +  if (reset) { 
 +    nextValue = 10
 +    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 =====
  
 ''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:filo|FILO() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/fifo.1788785565.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki