buffer holds output value. It only changes when delay timer is done. pulse-on-change restarts delay timer every time IN changes.
As mentioned before, this will skip changes if IN changes faster than T.
The FIFO (First In First Out) queue method I mentioned is kind of like a conveyor belt. You drop your “thing” onto the belt and wait for it to fall off the end. If you have a longer belt, or run it slower, you will have a longer delay.
Coding the FIFO ran into issues. If you update all the buffers in the queue at the same time, you are likely to end up with the same value in each queue positions instead of shifting values one position. The obvious way to handle this is to use defer to delay the pulse to the next queue position, so you end up with something like this:
New value is fed in to the left and oldest value is right-most buffer-MEM (which will be your output). The pulses need to start at the right to update output value, then work their way left updating each queue position. This works great for the first 4 positions, but XOD apparently doesn’t like a long chain of defer nodes; the last one on the left never pulses
It shouldn’t make any difference, but creating a new buffer node with a delayed DONE pulse seems to work. I just called this new-buffer:
NOTE: XOD also doesn’t like chaining generic pins, so I could not make new-buffer use generic pin. I had to specify the boolean pin needed for this program.
Now I can create my wait-and-run node:
This is a debug version. Rather than having input pins, it has tweak nodes so I can change values while running in debug. Instead of a single output pin, it has multiple watch nodes so I can see what it is doing. To use it in your program, replace tweak nodes with input pins, replace the right-most watch node with an output pin and just delete the other watch nodes.
Because the queue size (conveyor belt length) is fixed, I adjust the tick timing (conveyor belt speed) based on how long you want the delay. The divide by 5 node calculates how often to pulse given the delay time you desire using a 5-value FIFO queue (5 buffer nodes). If you specify 5 second delay, it will pulse every second. If you specify 10 second delay, it will only pulse every 2 seconds. Note that you will miss any input transitions that happen between these pulses. If you need greater accuracy AND a long delay time, you will need to add more buffer nodes and adjust the divide node to match. 10 buffer nodes with a 5-second delay will divide the delay time by 10 and pulse every 0.5 seconds. Things can quickly get out of hand, though. A 20 second delay with 0.25 second resolution would require 80 buffer nodes.
Using the queue gets you a true delay for each change (limited by the accuracy of the pulse interval), but uses a lot more memory. If input changes will always be slower than delay time, the 1st simple solution is better. You need to know the requirements of your particular program to determine which is the “best” solution for your program. If input can change faster than your delay and missing changes would be disastrous, the first option is very bad. If missing pulses is bad & using enough memory for queue is just as bad, then you will need to find another option.