View unanswered posts | View active topics It is currently Thu Nov 20, 2014 10:25 pm






Reply to topic  [ 3 posts ] 
Start, Reverse, Stop on one button? 
Author Message
Rookie

Joined: Fri Jan 11, 2013 7:49 am
Posts: 3
Post Start, Reverse, Stop on one button?
I'm a PLTW teacher and recently went to one of the Vex competitions in my area and saw that one team had their controller set up so that if they pushed a button on the controller and let go, a motor would run infinitely. They could also stop the motor, set it at a different speed, and put into reverse by doing the same thing with other buttons. A small group of students that I am taking to compete next week wants to do the same thing, but I don't know what the code would be. Any help?


Fri Jan 11, 2013 10:45 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Start, Reverse, Stop on one button?
Here is some pseudocode to get you started. It can be optimized more, but this will give you a general idea:
Code:
task main(){
  int motorPower;
  while(true){
    if(button 1 is pressed){
      motorPower = 127; // run motor full forwards
    }
    else if(button 2 is pressed){
      motorPower = 63; // run motor half forwards
    }
    else if(button 3 is pressed){
      motorPower = -127; // run motor full backwards
    }
    else if(button 4 is pressed){
      motorPower = -63; // run motor half backwards
    }
    else if(button 5 is pressed){
      motorPower = 0; // stop motor
    }
    motor[port1] = motorPower
  }
}

_________________
sudo rm -rf /


Fri Jan 11, 2013 11:58 am
Profile
Rookie

Joined: Fri Jan 11, 2013 7:49 am
Posts: 3
Post Re: Start, Reverse, Stop on one button?
Thank you so much! I put that up on my projector and my students saw that and got straight at it. They loaded it onto the Cortex and it works the way that they wanted it to. :bigthumb:


Fri Jan 11, 2013 7:26 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.