06-13-2014 09:06 AM
hey guys,
I just need a quick review on simple counter app. The main idea is that when user clicks on the button (+) the counter increments +1 and when user clicks button (-) it decrements. In any case the value should remain between 1-11 and should be in sequence, that means 1-2-3-4.....-11 or in reverse oder 11-10-9....-2-1 ... soo I came up with this solution that I am attaching but I want to know if there is a much simpler way of doing this.
Best Regards
Solved! Go to Solution.
06-13-2014 09:29 AM
Yes, there is.
Mike...
PS: Sorry, I couldn't help myself...
To begin with, use events to catch the button presses.
Next, store the counter value in a shift register on the loop.
Finally, use the Min-Max Value function to constrain the count in the limits you specified.
06-13-2014 09:34 AM - edited 06-13-2014 09:35 AM
@nolsqn wrote:
... but I want to know if there is a much simpler way of doing this.
There definitely is!
You don't need any local variables.
You don't need any subVIs
You don't need any comparison operations
You don't need to consume 100% CPU.
Code could proably fit on a postage stamp!
Try it!
06-13-2014 09:40 AM
hi mike,
i cannot use even structure as the boolean buttons actually later will be digital inputs. but i will update the VI with max -min function 🙂 and post the new version later
regards
06-13-2014 09:41 AM
hi alten,
any example you can tell me for reference ?
regards.
06-13-2014 09:43 AM - edited 06-13-2014 09:45 AM
You can create what are essentially value change events on digital IO points -- and don't forget to lose the local variables and hold the number in a shift-register...
Mike...
06-13-2014 09:44 AM
Get rid of the local variables
You only need one shift register to store the single value that you need not one for both + and -
No need for the two sub VI
Look at using
Event Structure
Quotient & Remainder
I have put all the stuff you need in this VI and left it to you to figure out how to wire it up.
06-13-2014 09:47 AM
hi omar,
I appreciate your design but as I said later my boolean buttons will be replaced with DI , hence I cannot use event structure.
06-13-2014 09:49 AM - edited 06-13-2014 09:50 AM
nolsqn wrote:any example you can tell me for reference ?
Well, this is obviously homework, so you need to make sure you understand every little wrinkle of the code. Try this.
If you don't want to use an event structure, it would be simple to adapt using a case structure. You also need to simulate the off-on transition.
06-13-2014 09:55 AM
Hi alten,
as far as I know Digital inputs from a DAQ card doesnt work with event structure, so I could have used event structure from start as well, but since I will be using DI's later thats the reason for a solution.
p.s its not homework, i was just hoping to see if I can implement it in a more better way.