View unanswered posts | View active topics It is currently Fri Aug 22, 2014 9:55 am






Reply to topic  [ 1 post ] 
Making Servos Stay in Place 
Author Message
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Making Servos Stay in Place
A few rookie teams were asking how to make a servo move to a specific place at the click of a button. I thought I would post how I usually do this. Here some some that will make the servo move to 100 and stay there when button 6U is pressed, and move to to 20 and stay there when button 6D is pressed.

Code:
task main(){
  int upperLimit = 100;
  int lowerLimit = 20;
  bool isUp = false;
 
  while(true){
    isUp = vexRT[Btn6U] ? 10 : vexRT[Btn6D] ? 0 : isUp;
    servo[arm] = isUp ? upperLimit : lowerLimit;
  }



Or, a slightly advanced version would be:

Code:
task main(){
  int upperLimit = 100;
  int lowerLimit = 20;
  int servoVal = lowerLimit;
 
  while(true){
    servo[arm] = servoVal = vexRT[Btn6U] ? upperLimit : vexRT[Btn6D] ? lowerLimit : servoVal;
  }
}

_________________
sudo rm -rf /


Tue Nov 09, 2010 4:59 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

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.