Per Erik Strandberg /cv /kurser /blog

Coming from text-based programming can be a good thing when using Labview - but let's face it: loops are weird in Labview so let's take a look at them in this little example.

The goal of this exercise in the control panel

This control panel might look a little frightening but it is pretty straight forward. The top slider is the fraction of the LEDs that should be lit. Then there is a two dimensional array of LEDs. The delay is the millisecond sleep that will be issued between each update. I also compute the expected number of active LEDs and the actual amount. In the bottom left there is also a stop button.
http://www.pererikstrandberg.se/blog/labview_loops/control_panel.png

Looking at the block diagram and the loops

As you can see there are three loops in this code. An outer while loop with a for loop in it - there is also a second for loop inside the first.

The while loop is stopped by the stop button in the lower right. It is also in the while loop that the Expected number of active LEDs is computed - with no need for the inner loops. As you can see in the top right corner this loop is also responsible for the sleep - by using the delay slider. We will come back to the number of actual active LEDs later.

The very core of this code is a comparison of a random number and the value provided by the fill slider. The boolean value from this comparison is one bool. As it is propagated out of the inner loop the wire thickens to indicate that it is now an array in one dimension, and as it leaves the second loop it is even thicker to indicate that it is now an array in two dimensions. This 2D-array is then used to fill our LED-array. You can think of this as used for illustration purposes only - the array can exist without the LEDs (removing the LEDs does nothing to the rest of the program).

The number of active LEDs is now computed using a conversion from boolean to number and then a sum node.
http://www.pererikstrandberg.se/blog/labview_loops/block_diagram.png

This fun little example can be downloaded here: [1]


See also Labview Loops And Arrays
This page belongs in Kategori Programmering