From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Momentary switch

Hi,

I'm new to CVI.
Any way to implement a push button with momentary action?
Only turn on when click on button, off upon release it.

Any example can I refer to?
0 Kudos
Message 1 of 4
(4,374 Views)

The "Command button" does just this.  It's momentary.  

 

Or if you prefer, you could use any of the "Toggle buttons" or "Binary switches" and get this behavior by using a combination of the EVENT_LEFT_CLICK and EVENT_LEFT_CLICK_UP.  When you get the click up event, you could forcibly reset the switch control's position back to OFF.

0 Kudos
Message 2 of 4
(4,363 Views)

Hi,

 

I followed using  EVENT_LEFT_CLICK and EVENT_LEFT_CLICK_UP to light a LED.

But when I press the toggle button, the button did not respond properly. Some lag occur & button only depress when click on its label. Only when double-clicking the button, it will then depress.

 

 switch (event)
 {
  case EVENT_LEFT_CLICK:
   SetCtrlVal(panelHandle, PANEL_LED, 1);
   SetCtrlVal(panelHandle, PANEL_TOGGLEBUTTON_2, 1);
   break;
   
  case EVENT_LEFT_CLICK_UP:
   SetCtrlVal(panelHandle, PANEL_LED, 0);
   SetCtrlVal(panelHandle, PANEL_TOGGLEBUTTON_2, 0);
   break;
    
 }
 return 0;

0 Kudos
Message 3 of 4
(4,354 Views)

Yes, that would be normal behavior for a Toggle button.  Toggles are not momentary: they keep their state.  But to get behavior you want, I've made you a sample project, with both Command and Toggle buttons:

 

 

Message 4 of 4
(4,342 Views)