ROBOTC.net forums
http://robotc.net/forums/

Making Servos Stay in Place
http://robotc.net/forums/viewtopic.php?f=11&t=2735
Page 1 of 1

Author:  magicode [ Tue Nov 09, 2010 4:59 pm ]
Post subject:  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;
  }
}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/