// Maurice Ribble // 4-6-2008 // http://www.glacialwanderer.com/hobbyrobotics // This code depends on the Servo Software Library. You can get // this lib from http://www.arduino.cc/playground/ComponentLib/Servo // To use this app just send the board a number followed by an 's' // to set the angle of the servo (0-180 are valid) #include // This is the pin you need to attach the servo to #define SERVO_1_PIN 2 Servo g_servo1; void setup() { pinMode(SERVO_1_PIN, OUTPUT); g_servo1.attach(SERVO_1_PIN); Serial.begin(9600); Serial.println("Enter number and press 's' to send it to servo."); } void loop() { static int val = 0; if (Serial.available()) { char ch = Serial.read(); switch(ch) { case '0'...'9': val = val * 10 + ch - '0'; break; case 's': g_servo1.write(val); Serial.print("Servo1 is set to: "); Serial.print(val, DEC); Serial.println(" degrees"); val = 0; break; } } Servo::refresh(); // Should try to call this every 20 ms to insure servo stays set }