Jump to content

Increment once on boolean change


Recommended Posts

Hi guys,

I'm designing a robot which turns on a base. To determine the position it's in, I use a button (NI-DAQ) which is pressed every few second.

Now I want to count the amount of button presses.

I have the a DAQ-module (which reads the inputs) running in a while loop. When I increment a counter using a case-structure when the button is pressed, my increment is repeated every clockpulse.

I tried using an Event structure to execute when the boolean changes its value but that didn't work.

Using a second boolean as control to stop the incrementation didn't work well either.

Any ideas on how to do this?

Link to comment

Sounds to me like you need to implement a SR(shift-register) in your while loop to hold the last value of the Boolean in question and do a comparison between the boolean in question it's previous value.

Example

Thank you Ryan, while loading this topic, I came up the a similar solution involving a shift register and a control boolean. This seems to work.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.