/* Temporary Servo Function * ------------ * by Tom Igoe and Jeff Gray * * Passes a variable to a function that runs a servo on pin 9 * (NOTE) This is a temporary fix until Wiring Servo libary examples exist */ int servoPin = 9; int myAngle; // angle of the servo (roughly in degrees) 0 - 180 int pulseWidth; // function variable servoPulse(int pinNumber, int angle); // function prototype void setup() { pinMode(servoPin, OUTPUT); // set servo pin as output } void loop() { for (myAngle=0; myAngle<=180; myAngle++) { // cycle through every angle (rotate the servo 180 slowly) servoPulse(9, myAngle); } } servoPulse(int pinNumber, int angle) { // this is a function for determining our pulsewidth for the servo pulseWidth = ((angle/180.0) * 1200.0) + 200.0; // this determines our delay below (for a standard pot) digitalWrite(pinNumber, HIGH); // set servo high delayMicroseconds(pulseWidth); // wait a very small amount (determined by pulsewidth) digitalWrite(pinNumber, LOW); // set servo low delay(20); // refresh cycle of typical servos (20 ms) }