Start and End times


Recommended Posts

Sure. I'm going to assume you have a channel called "Button" that is a digital input that reads 1 when the button is pressed and 0 when it is not.

1) create a new sequence called "StartUp" and mark it AutoStart and add this script. If you already have an autostart sequence, just put this script somewhere in it:

global starttime = 0
global endtime = 0

2) go to the Button channel's event by clicking the channel in the workspace then selecting the event tab.

3) enter this script:

if ((button[0] == 1)  && (button[1] == 0))
   // button pressed:
   if (starttime == 0)
	  starttime = systime()
   else
	  if (endtime == 0)
		 endtime = systime()
	  endif
   endif
endif

4) create a new button component on the screen and in the Action for the button select quick sequence and put this script:

starttime = 0
endtime = 0

5) create a couple of variable value components with the following expression:

iif(starttime == 0, "Not pressed", formattime(starttime))

repeat for endtime replacing starttime with endtime. The iif() is the inline if function standard to most programming languages. If starttime equals 0, it will display Not Pressed, but if it does not equal zero it will display the starttime.

One important note: if your acquistion speed is too slow on the button, it is possible that you might miss the button press. Don't go faster than maybe 0.1, and if that's not fast enough you may have to use a counter, or you might be able to use a big capacitor to make the signal last long enough for your DAQ device to read it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.