LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

increment only once when statement true

Hi so my problem: i want to do a calculation of 1rm (maximum power with 1 reputation in lifting exercise for example). For that ineed to count the reputations. I have a distance sensor between 0 and 50. You start the reputation from zero, andwhen you fully ligt the weight you are at 50, than back to zero.

 

So when i have the sensor data at 20, or more, i want to increase my reputation counter by one, but onyl once. And put this number to the equation. But i'm new to labview and cant figure out how to increment my variable only once! 😞

 

I posted a picture about my vi. the whole thing is inside a while loop.The 1rm is the goal at the output of equation. x is a data coming from somewhere else thats okay, and y is the numberof reputation, which i dont have. Theproblem with this one is that it will count countiniusly if the sensor is higher than 20. But i only want to count once when higher than 20, than wait until the value goes udner 20, and then count again once if its higher than 20 again.

screenshot from vi

 

Message 1 of 8
(5,926 Views)

Hi,

      your programming way can be improved. and this is purely a simple solution for your question. 

 

      In place of the greater comparison block place a In Range and Coerce the issue will be solved refer to the below image.  on the false case either connect a constant or make it  as "use default if unwired"

 

sol.png

 

Kudos Welcome 🙂

 

Certified-LabVIEW-Associate-Dev_rgb (1).jpg

Certified LabVIEW Developer
Best LabVIEW Programmer @NIDAYS 2015
0 Kudos
Message 2 of 8
(5,914 Views)

Hi!

 

Thanks for your reply!

 

However the sensor can send the 20-21 for like a second, and in that case will it count more times?

0 Kudos
Message 3 of 8
(5,907 Views)

You need more than that.  You need a shift register that stores a boolean value that tells whenever you have added 1.  So only add 1 when the number is > 20 and NOT the boolean value  (So a boolean false with NOT becomes true.)  Set the boolean to True.

 

Whenever the value goes less than 20, then reset the boolean in the shift register to False.

 

 

0 Kudos
Message 4 of 8
(5,904 Views)

@Oiver91 wrote:

Hi!

 

Thanks for your reply!

 

However the sensor can send the 20-21 for like a second, and in that case will it count more times?


see to the code properly i haven't added include upper limit so it will only check for 20. only if you right click on In range and Coerce and select include upper limit it will count 21. unless you do that the value will take only the lower limit ie 20.

 

Certified-LabVIEW-Associate-Dev_rgb (1).jpg

Certified LabVIEW Developer
Best LabVIEW Programmer @NIDAYS 2015
0 Kudos
Message 5 of 8
(5,895 Views)

Basically the same as RavensFan's code, but I find the Feedback Node to be easier to read in situations like this.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 8
(5,865 Views)

What about the nice PtByPt-BooleanCrossing function?

Its made to detect rising/falling edges of boolean signals!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 8
(5,853 Views)

Finally!!!! Yes.  This is exactly what I was looking for.  Thank you so much!!!

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