rudydiaz Posted February 23, 2010 Share Posted February 23, 2010 I would like to set up two switches Switch A and Switch B and have daqfactory tell me how many times Switch A has been pressed and how many times switch B was pressed and then final calculate for me the percentage times that switch B was pressed compared to Switch A. I have no scripting experience whatsover so please be very basic in your explanation.. Thanks Rudy Link to comment Share on other sites More sharing options...
AzeoTech Posted February 24, 2010 Share Posted February 24, 2010 Well, assuming you don't need a lot of precision in the time measurements and your switches are switched for long durations (i.e. not momentary), then do this: 1) create two channels, both digital input, to read the switch status. Lets assume you call them SwitchA and SwitchB. Lets also assume that you have a timing of 0.1. 2) create a new sequence called "StartUp", mark it Auto-start, and put this: global switchATime = 0 global switchBTime = 0 3) next, click on "SwitchA" in the workspace under Channels, then click on the Event tab to get to SwitchA's event. Put in this line of script: switchATime += switchA[0] * (switchA.time[0] - switchA.time[1]) This uses boolean math, adding the time if switchA == 1, but not if its 0. 4) repeat for switchB, replacing all the A's with B's 5) now you can create screen components, namely Variable Value components to display these values. The units are seconds. You can also create one to display the percentage by putting in the appropriate calc: switchBTime / switchATime or, if you want as a percentage of total time clicked: switchBTime / (switchATime + switchBTime) Note that the precision of this measurement is = to the Timing interval you specify. Note also that this will not work with streaming data, only polled data, so the smallest Timing you can use is probably 0.02. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.