Example Code

Using One Button to Control Two States Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

Use this template to build a producer/consumer design pattern with events to produce queue items. Use this design pattern instead of the User Interface Event Handler pattern for user interfaces when you want to execute code asynchronously in response to an event without slowing the user interface responsiveness.


Description

This VI demonstrates the programming necessary for a single button to programmatically control two states. This VI also demonstrates the power of the event data node and how it can be utilized. This provides an alternative method for creating the same number of buttons as cases that you want to programmatically control. Depending upon the application this could provide a much more intuitive user experience compared to a program with many buttons with various functionalities. The cases in the case structure (consumer loop) are only designed to show how the program works. The code in these states can e replaced with the functionality the user wants to actively enable.


Requirements

  • LabVIEW 2012 (or compatible)

Steps to Implement or Execute Code

  1. Download the .zip folder
  2. Unzip the folder and open the "Example.lvproj"
  3. Open the "Main.vi"
  4. Run the VI and play with the buttons

Additional Information or References

VI Block Diagram

OneButton.PNG

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Sam Burhans
Senior Product Manager
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.