ROBOTC.net forumshttp://robotc.net/forums/ servo helphttp://robotc.net/forums/viewtopic.php?f=62&t=11045 Page 1 of 1

 Author: steammad [ Fri May 01, 2015 3:29 pm ] Post subject: servo help HiI was wondering if anyone can help me. I am looking for code that will allow me to operate two servos.I would like to have it operated by a reed switch.Basic it would go like this.reed switch activated, servo 1 would turn 90 degrees & stop, then after the first servo has finished, servo 2 would then turn 90 degrees & stop. When the reed switch is activated again. Servo 2 would rotate back 90 degrees & stop, then servo 1 would rotate back 90 degrees & stop. I would also need the servos to rotate at say 150ms per positionany help welcomed ps I have an UNO

Author:  JohnWatson [ Mon May 11, 2015 2:21 pm ]
Post subject:  Re: servo help

 steammad wrote:reed switch activated, servo 1 would turn 90 degrees & stop, then after the first servo has finished, servo 2 would then turn 90 degrees & stop. When the reed switch is activated again. Servo 2 would rotate back 90 degrees & stop, then servo 1 would rotate back 90 degrees & stop. I would also need the servos to rotate at say 150ms per position

You actually have most of what you need right here: all you need to do is put it in a psuedocode format, then fill in the psuedocode with actual code.

 Code:bool hasTurned90 = 0;   while(1==1)   {      if(reed switch is activated AND hasTurned90 is 0)      {         turn servo1 90 degrees         wait1Msec(amount of time to complete movement);         turn servo2 90 degrees         wait1Msec(amount of time to complete movement);         hasTurned90 = 1;      }      else if(reed switch is activated AND hasTurned90 is 0)      {         turn servo1 90 degrees (back)         wait1Msec(amount of time to complete movement);         turn servo2 90 degrees (back)         wait1Msec(amount of time to complete movement);         hasTurned90 = 1;      }   }

This is one way to do this code, and you may need to tweak it to fit what you want to do. There is a variable known as a state counter to see if the servos have turned already, and each if/else if statement checks to see if the variable is at a zero value (the servos are currently at a 0 degree position) or 1 (servos are at a 90 degree position).

Each servo will be turned to the correct position, with a wait1MSec command giving each time to reach their target value(s). You will need to determine the amount of time you want to give each servo to ensure that it reaches the target value before the next servo starts moving.

 Author: theenggprojects [ Wed Nov 18, 2015 10:39 pm ] Post subject: Re: servo help you should read this one out http://www.theengineeringprojects.com/2 ... oteus.html

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