View unanswered posts | View active topics It is currently Mon Sep 01, 2014 10:05 pm






Reply to topic  [ 3 posts ] 
how do I check for double button push on vex controller 
Author Message
Rookie

Joined: Sun Feb 24, 2013 9:57 pm
Posts: 2
Post how do I check for double button push on vex controller
hello.

I am trying to code my robot's lift to behave differently based on whether I press the selected button once or I just hold the button in. I understand how to code the If statements for performing various actions, but I cannot figure out how to code a check for two button touches in a set time versus holding the button.

thanks for your help on this.


Sun Feb 24, 2013 10:03 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 566
Post Re: how do I check for double button push on vex controller
This is a perfect case of how psuedocode can ease the programming process. In essence you want to:

Check IF a button is pressed, WAIT a certain amount of time, and IF the button is pressed still execute some code; ELSE, execute some other code. Putting this in psuedocode format will net us:

Code:
if(button is pressed)
{
  wait

   if(button is pressed still)
    {
     do this code
    }

   else
    {
    do this code instead
    }
}


From here, you should be able to add in the actual code to suit your specific setup (depending on if/what the sensor names are, for instance). One thing to note that this code will probably need to be up in a loop, and you will have to make sure that the wait command isn't too large (otherwise it will halt the program upon button press for x amount of time, where x is the time specified in the wait command.

_________________
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


Mon Feb 25, 2013 10:33 am
Profile
Rookie

Joined: Sun Feb 24, 2013 9:57 pm
Posts: 2
Post Re: how do I check for double button push on vex controller

    So i understand that pseudocode. Two issues. in the first iff statement I am checking to see if the button is still pushed. I think that that state should be in the else because the condition where I have pressed once then pressed again to stimulate a special behavior is more restrictive.

    The pseudocode for just that segment must be something like this:

    IF (button pushed and released)
    {
    check to see if button is pressed again within a set amount of time (in my case if I were to press the button a second time, I would cause the lift to operate until a limit switch is activated - limit switch code is already done)
    }

    Else if (button pressed and held for a longer time)
    {
    Perform a standard function (in my case this would be to move the lift up until i release the button)

    else
    {
    do nothing
    }
    ////////////////////////////////////

    so you can see that there has to be some sort of timer to check against, but I can't get my head around the test that would allow me to check if a button were pressed then released then repressed and released. This is similar to a mouse double click on a computer, but not being a programmer per se, i don't know how that code works let alone knowing how to make it work in RobotC.

    Thank you,


    Mon Feb 25, 2013 1:44 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.