Programming with LabVIEW
Online LabVIEW Evaluation: Exercise 1Before You Begin
We recommend you use the following equipment to complete the exercise:
- A mouse for easy maneuverability
- Two monitors, one to show the exercise steps and another for LabVIEW
Excercise Instructions
- Create a new VI by selecting File > New VI
This step creates a new VI, which is made of two windows. The Front Panel serves as the user interface, and the Block Diagram contains the program code in a graphical form.
- Building the User Interface
- Place a Numeric control by right-clicking the Front Panel, navigating to the Numeric palette, and selecting Vertical Pointer Slide.
- Place the control on the Front Panel
Double click the label "Slide", and type the new label, Temperature (F).
- Right-click the Slide control and select Properties. In the Scale tab, change the scale range maximum to 200 and click OK.
The controls Palette that appears when you right-click includes all the necessary elements to build your user interface. Take some time to explore the different controls and indicators available.
Tip: You can resize controls and indicators; when your curser is on an object, resizing handles appear at the points from which you can resize. Use these handles to resize the control to your liking.
- Right-click the Slide control and select Visible Items >> Digital Display.
- Add an indicator, where the user can see the results or outputs of the program displayed. In this exercise, it will be a Numeric Indicator where the converted temperature in Celsius will be displayed.
- Right click the front panel, navigate to Numeric and select Tank.
- Once placed on the Front Panel, right-click and select Change to Indicator,.Then, select Properties. In the Scale tab, change the scale range maximum to 100 and click OK.
Take some time to explore the different properties you can modify.
- Place the thermometer on the front panel and resize it to your liking.
- Change the label to "Temperature (C)."
- Right-click the temperature indicator and select Visible Items >> Digital Display
- Place a Numeric control by right-clicking the Front Panel, navigating to the Numeric palette, and selecting Vertical Pointer Slide.
- Creating the Block Diagram
- Right click the block diagram and navigate to Programming >> Numeric >> Subtract.
When you right-click the block diagram, the Functions palette appears. Here you will find all the necessary elements and functions to create the logic of your program. Take some time to explore the different functions available.
- Place the subtract function on the block diagram, in a space between the control and the indicator.
- Right click the block diagram and navigate to Programming >> Numeric and add the Multiply function.
- Right click the block diagram and navigate to Programming >> Numeric and add the Divide function.
- Wire the code to create data flow
- Hover your cursor over the Temperature (F) control. When the node on the right appears, click it then move your cursor to the top input node on your Subtract function and click it to connect a wire between the control and the function.
- On the lower input node of the Subtract function, right-click and select Create Constant. Double click the constant and type 32.
- Similarly for the Divide function, create a constant for each of the input nodes, changing the top one to 5 and the bottom one to 9.
- Connect a wire from the output of Subtract to the top input of Multiply.
- Connect a wire from the output of Divide to the bottom input of Multiply.
- Connect a wire from the output of Multiply to the Temperature (C) Indicator.
We now have a functional program that can take the input temperature you select, convert it to Celsius, and display it on the Temperature (C) indicator. Let's test it out!
- Move the Temperature (F) slider to 75 (or type out 75 in the digital display), then select the Run button. The program will run, and the Temperature (C) thermometer should now read 23.8889.
- Writing the code: Using Loops
- Right-click on the Block Diagram>>Programming>>Structures>>While Loop.
- As you place it on the Block Diagram, drag the loop to encapsulate the existing code.
- Right-click on the Block Diagram > Boolean > Stop Button.
On the block diagram, you now have two terminals corresponding to the control and indicator we placed in the previous step. We'd like to pass the input from the Temperature (F) control through a quick calculation, converting it to a Celsius, and finally to the Temperature (C) indicator.
The conversion equation is T(C)=[T(F)-32*[5/9], which means we need a subtract, a multiply and a divide function in our program.
To create the logic, next we need to add our constants and wire the functions together.
When you hover your cursor on each function, input and output nodes appear. For example, the Subtract function will take in 2 inputs and output the difference between them.
As a final step, we'd like to allow the user to continuously change the input and see the converted temperature until they decide to end the program. To do this, we will use a While loop.
On the bottom right corner of the loop, you'll find a Loop Condition terminal, which determines when the loop stops running. In this exercise, we want to give the user control.
This step creates a Stop button on the front panel.
Tip: On the front panel, move and resize the Stop button for better accessibility and a friendlier user interface
Your program is now ready to run.
- Click the Run button on Front Panel toolbar.
- Move the Slide control on your Temperature (F) control, and you can see the corresponding temperature in Celsius displayed on the Temperature (C) Indicator
- After you are done, click the Stop button to end the program.
Where to Go Next
Resources
To continue learning about using LabVIEW, NI provides you with a number of options.
Learn More About Programming in LabVIEW
Browse example code to use as a starting point then modify it to fit your needs.
Finding Example VIs in LabVIEW
LabVIEW Example Code Repository
Explore the LabVIEW environment, dataflow programming, and common LabVIEW development techniques.
Learn to use common design patterns to successfully implement and distribute LabVIEW applications for research, engineering, and testing environments.
Find Answers to Your Questions
Ask all your coding questions and get suggestions about how to improve your programming.
LabView Discussion Forums
Get answers to common questions and troubleshooting tips from NI technical support engineers.
Search Knowledgebase
