When programming with loops, you often must pass data from the current iteration to the next iteration. Shift registers are perfect for such tasks.
For example in the code below, we use a shift register to gradually change the servo’s position in each iteration of the while loop. It gets incremented by steps of 0.01 up to value 1, then it resets to 0.
Let’s walk through the code. First, we initialize the left shift register with a value of 0. This means that 0 gets used in the first iteration of the while loop. It then propagates through the code, which yields the result 0.01. This is then pushed to the shift register on the right. The shift register takes this number and brings it around to the register on the left; take a look at the black arrows for better visualization. The left shift register takes this new value and passes it back into the while loop code. Notice that constant 0 is ignored at second iteration and any future iteration. Once again, this is an initialization constant; thus, it is used only in the first loop.
Click here to learn more about shift registers in LabVIEW.
