View unanswered posts | View active topics It is currently Wed Oct 22, 2014 12:34 pm






Reply to topic  [ 3 posts ] 
Latching and unlatching a button 
Author Message
Rookie

Joined: Thu Mar 07, 2013 5:22 am
Posts: 2
Post Latching and unlatching a button
Trying to use one button to activate a pneumatic by touching it rather than holding it, and then touching the same button to deactivate the pneumatic. Have tried the attached code but it seems the variable to hold the value to activate the pneumatic sometimes initializes and at times it doesn't. Thanks for your help


Attachments:
File comment: The value of "hold" is used to activate the pneumatic
Latching.c [198 Bytes]
Downloaded 133 times
Thu Mar 07, 2013 2:37 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 592
Post Re: Latching and unlatching a button
You may be running into a property of buttons called 'debouncing'. Try the code below, which will add a pause command that should help accommodate for the debouncing:

Code:
int X = 0;
int hold = 0;

task main()
{
   while (true)
   {
      if (vexRT[Btn5U] == 1 && X == 0)
      {
         hold = 1;
         X = 1;
         wait1Msec(20);
      }
      
      if (vexRT[Btn5U] == 1 && X == 1) 
      {
         hold = 0;
         X = 0;
              wait1Msec(20);
      }
      
   }
}

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Fri Mar 08, 2013 4:17 pm
Profile
Rookie

Joined: Thu Mar 07, 2013 5:22 am
Posts: 2
Post Re: Latching and unlatching a button
Thanks for the help and information. Will give it a try.


Sat Mar 09, 2013 2:14 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.