## Tutorial: LabVIEW Basics

Before starting this lesson, you need to have LabVIEW installed and ready to run. You can check to see if it is installed by going to Start»All Programs»National Instruments»LabVIEW 2010. This course assumes that you have never written a computer program, but you'll start programming right away! Have fun!

We are going to start learning how to program in LabVIEW by writing a program that will calculate the hypotenuse of a right triangle. You probably remember that the Pythagorean Theorem uses three sides of a right triangle, a, b, and c, where c is the hypotenuse.

Below is an example which is actually what we will be developing in LabVIEW. The sides a, and b are called legs of the triangle and c is the hypotenuse.

We can compute the length of the hypotenuse using the Pythagorean Theorem which is which means that . We have to start by creating the what the user will use to enter the values of a and b and the program will display the value of c. This is done in the front panel of LabVIEW. It is named front panel because a system such as a power generator has a front panel to display the status of the system. Make sure that LabVIEW is started and so that you see the Getting Started window.

You want to click File»New VI to create a new VI program. After you do that two windows appear, one is called the "front panel" and the other is called the "block diagram". It is best to tile these windows so they are both visible on the screen, and you can do that by pressing CTRL-T. The following steps tell you how to create the user interface on the front panel

1. Move your cursor over to the front panel. This screen is blank right now and you are going to add controls and indicators to it in the next step.
2. Controls are input values to the program and indicators are output from the program. We have two controls that the user can enter, these are "a" and "b", and we have one indicator, "c". Right click on the front panel screen and a control window similar to what is below will come up.

Move your cursor over to the front panel. This screen is blank right now and you are going to add controls and indicators to it in the next step.

1. Controls are input values to the program and indicators are output from the program. We have two controls that the user can enter, these are "a" and "b", and we have one indicator, "c". Right click on the front panel screen and a control window similar to the window below will come up.

In the Express section of this window there are two buttons that we will expand: The "Num Ctrls" contains all of the numeric controls available to you and "Num Inds" contains all of the numeric indicators. Click on Num Ctrls and then drag the icon that says "Num Ctrl" to the front panel. This will have the value of the "a" side and you can rename this control by double clicking the text above the control and typing an "a", the click anywhere on the front panel. This is how you can change the label above any front panel item. Do the same thing for the "b" side.

1. To create the indicator for the value of "c" select "Num Inds" in the Express window and then drag a numeric indicator, labeled "Num Ind" to your front panel. You can now arrange these controls and indicators like the Front Panel below.

2. Now we need to add the code to make the program take the values of "a" and "b" and compute "c". If we run the program like it is right now it will only print a value of zero for "c" because it isn't computing anything! Here are the steps to compute "c".
1. Move your cursor to the block diagram. This will be a window containing only the two controls for "a" and "b", and the one indicator for "c". When you add a control or an indicator to the front panel it also adds it to the block diagram. We will add the code to this now. The image below shows the actual block diagram that you are going to create.

1. Right click on the block diagram and a functions window will come up. We want to square the value of "a" and "b" and to do that you want to click on the small arrow at the bottom of the functions window. Then click on the Mathematics Numeric icon and then drag the "Square" icon to the block diagram.
2. To square the value of a, we have to connect the control containing the 'a' value to the "square" function. When you move the cursor to the right of the control a roll of wire will appear and you want to hold the mouse and drag it to the left of the square function.
3. To square the value of b, you want to do steps 2 and 3 with the value of b. After you do that you will have the a2 and b2 and the next thing to do is to add these two values together.
4. You want to add an "add" function to the block diagram and you can do this by right clicking on it, selecting Mathematics, clicking on numeric, and then dragging the "add" icon to the block diagram.
5. The add function has two inputs and one output. The inputs are always on the left and the outputs on the right. So take the output of where you squared "a" and connect it to the top input of the add function and then take the output of squaring "b" and connect it to the bottom input of he add function. You now have a2 + b2.
6. The next step is to take the square root of a2 and b2 and you can do this by right clicking on the block diagram, select mathematics, select numeric, and then drag the square root icon to the block diagram. There is a single output from the add function and you want to drag that to the input of the square root function.
7. The last step is to drag the output of the square root function to the indicator having the "c" value. This will take the value of sqrt(a2 + b2) and display it on the screen.
8. To run your program click on the run arrow at the top of the screen.

Congratulations! You have created a LabVIEW program!

Next