====== FIFO() ====== ''FIFO()'' outputs the first stored 16-bit data first. {{:en-us_commands:reference:fifo.svg?900|FIFO command operation flow}} ''bool FIFO(uint8_t fifo_id, bool IN, bool OUT, uint16_t input, uint16_t &output, uint8_t size, bool reset = false)'' ===== Commands ===== ^ Command ^ Arguments ^ Return Value ^ Operation ^ | ''FIFO(fifo_id, IN, OUT, input, output, size, reset)'' | ''uint8_t fifo_id'' — Buffer ID\\ ''bool IN'' — Store input on the rising edge\\ ''bool OUT'' — Output on the rising edge\\ ''uint16_t input'' — Word to store\\ ''uint16_t &output'' — Reference variable receiving the output\\ ''uint8_t size'' — Buffer size\\ ''bool reset = false'' — Reset the buffer | ''bool'' | Outputs the first stored 16-bit data first. | ===== 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. uint16_t nextValue = 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, removedValue, 4); // 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); } } Pushing to a full buffer or popping from an empty one fails. ===== 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. ===== Built-in Commands in the Same Category ===== * [[:en-us_commands:reference:filo|FILO() View detailed description]] [[:en-us_commands:builtin|← Built-in Command List]]