Count to Three

Just like a programmer starts off printing "HELLO WORLD" on the screen, in LabVIEW you can start off by learning to count to three. It's not easy or intuitive to find a way to count between two numbers. The key words are "Quotient & Remainder." On the Block Diagram hit CTRL and then SPACEBAR at the same time to pull up the Quick Drop dialog box. Type in Quotient & Remainder. It should find it by just typing in Quo....
Now add a While Loop around the Quotient & Remainder.


We will use the iteration (i) terminal from the while loop to show the current loop count. The iteration terminal starts with zero on the first sequence. We connect a wire from the iteration (i) terminal to the X input of the Quotient& Remainder.

We need to add an upper limit number to the Y input of the Quotient & Remainder.  So Right-Click your mouse over the Y input and Create a Constant.  We want this vi to count from 0 to 3.  Put a 4 in the constant box.  The output will count from 0 to 3 because the first count will be the zero and the fourth count will be the number 3.

Right-click on the upper right output connector of the Quotient & Remainder and create an Indicator.  This numeric indicator will be shown on the Front Panel.  This is where the numbers will be seen.  If you want to use this number for another operation, just add a wire and connect to another vi, or a graph, etc.

You will need to add a Stop button to the front panel for this example and wire it to the Stop if True function of the While Loop at the lower right hand corner.  Let's also slow it down a little so we can see the operation working.  Add a Wait Until Next ms Multiple icon with 500 as a constant wait time.

Hit run and watch the numeric indicator count from 0 to 3 on the Front Panel.  Hit the Stop button to end the process.

Thanks for learning how to Count To Three using LabVIEW with me.  Feel free to leave a comment.

No comments: