LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to increase a number by 1 in a loop

Solved!
Go to solution

Hi this is sligthly more difficult than the title reads i think.

 

I have a while loop reading the com port to detect a switch being on or off by doing an rs232 loopback

if i get an error its off,  no error on.  

 

what i want to do is increase a number by 1 when the switch is on the off position, but at the moment 

the number just constantly increase as the "+1" function is in a loop.  How can i make it only increase

the number once.

 

The loop needs to constantly run if the switch is on or off

 

Hope this makes sense,  i have attached a picture of what it does now

 

I look forward to your suggestions.

0 Kudos
Message 1 of 8
(5,111 Views)

You can add a shift register that will remember the last state of the switch. If the last state of the switch was True, but now is False, you can increment your counter.

 

-Cristian

Message 2 of 8
(5,095 Views)
Solution
Accepted by topic author theno1dj

One way is to use a flag.  I change the flag to true as soon as the thing turns on, then false again until the next time it's turned on.

 

There may be better solutions, but this is the first thing that came to mind.

 

EDIT: My example is what Cristian said.  Beat me to it.

Message Edited by elset191 on 11-20-2009 08:41 AM
--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 3 of 8
(5,092 Views)
What about the First Call? function (in the Synchronization palette). It lets you do something once then forget it on subsequent calls. Just wire it to a case statement with your incrementor in it.

 

 

edit: After re-reading your post I think you need Tim's idea above, not the First Call? function, but just in case you didn't know about it, there it is! Smiley Happy

 

 

Message Edited by Broken Arrow on 11-20-2009 08:57 AM
Message Edited by Broken Arrow on 11-20-2009 08:58 AM
Richard






0 Kudos
Message 4 of 8
(5,073 Views)
I think he wants it to increment every time the switch is flipped.  Not just the first time.  At least, that's how I understood it.
--
Tim Elsey
Certified LabVIEW Architect
Message 5 of 8
(5,066 Views)

elset191 wrote:
I think he wants it to increment every time the switch is flipped.  Not just the first time.  At least, that's how I understood it.

 

Yep, I was editing while you responded Smiley Happy
Richard






0 Kudos
Message 6 of 8
(5,056 Views)

Cheers tim that is exactly what i wanted,

 

so simple but im struggling this friday afternoon.

 

Thank you very much

0 Kudos
Message 7 of 8
(5,055 Views)

oops too late.

 

You guys are fast.

 

An example follows.

0 Kudos
Message 8 of 8
(5,035 Views)