From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

FIRST Robotics Competition Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Use of Shift Registers to Pass Data Between Loop Iterations.

When programming with loops, you often must pass data from the current iteration to the next iteration. Shift registers are a great tool for these types of tasks.

 

For example, the code below uses 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.  

 

The code first initializes the left shift register with a value of 0, which will be used for 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; 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. For example, in the second iteration of the while loop the left shift register will have a value of 0.01. Notice that constant 0 is ignored at second iteration and any future iterations. Once again, this is an initialization constant; thus, it is used only in the first loop.

 

To include shift registers in your code, right click the tunnel you would like to pass data to future iterations on the loop you are using and select Replace with Shift Register.

 

Snippet.png

 

Further explanation of shift registers can be found in the link below:

Shift Registers: Passing Values between Loop Iterations