Example Code

Find how long is a button pressed in 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

1. Overview:

This example shows how to code a program that calculates how long a button is pressed using an event structure.

 

2. Description: 

This VI uses the properties of the event structure to calculate the time a button is pressed. As the structure provides the time for the Mouse Down and Mouse Up events, the time between them can be calculated by taking a timestamp in the Mouse Down event and subtracting it to the timestamp provided in the Mouse Up event. This is how the code is implemented in this example.

 

3. Requirements

  • LabVIEW 2012 (or compatible)

4. Steps to Implement or Execute Code

  1. Run " Time While Button Pressed LabVIEW 2012 NI Verified.vi"
  2. Click OK Button and mantain it clicked. The Time Pressed (ms) will display the time elapsed.
  3. Click Stop to finish the execution

5. Additional Information or References 

VI Block Diagram

Block Diagram.JPG

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

Regards,
Efrain G.
National Instruments
Visit http://www.ni.com/gettingstarted/ for step-by-step help in setting up your system.

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