FILO() outputs the last stored 16-bit data first.
bool FILO(uint8_t filo_id, bool IN, bool OUT, uint16_t input, uint16_t &output, uint8_t size, bool reset = false)
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
FILO(filo_id, IN, OUT, input, output, size, reset) | uint8_t filo_idbool IN — Store input on the rising edgebool OUT — Output on the rising edgeuint16_t input — Word to storeuint16_t &output — Reference variable receiving the outputuint8_t size — Buffer sizebool reset = false — Reset the buffer | bool | Outputs the last stored 16-bit data first. |
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.
uint16_t nextNumber = 0; uint16_t lastNumber = 0; void setup() { Serial.begin(115200); } void loop() { if (!Serial.available()) return; const char action = Serial.read(); const bool store = action == 'a'; const bool retrieve = action == 'p'; const bool clearBuffer = action == 'c'; if (store) ++nextNumber; const bool ok = FILO(0, store, retrieve, nextNumber, lastNumber, 16, clearBuffer); // Store a number; on a pop signal, retrieve the last stored number. FILO(0, false, false, nextNumber, lastNumber, 16, false); // Return both inputs to LOW so the next character creates a new rising edge. if (retrieve && ok) Serial.println(lastNumber); if (retrieve && !ok) Serial.println(F("Buffer empty")); }
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.