analog stick help

Hi all,

I am trying to build a robot that uses analog sticks to control servos and I am able to have the arduino read the input of the analog sticks but I am not sure how to get the servos to respond to the values. If anyone has sample code for a similar project I would appreciate it.

Try the example sketch File->Examples->Servo->Knob. It does exactly what you want.

In simplified form:

#include <Servo.h> 
Servo servo;
 
const int joystickPin = 0;  // Analog pin for joystick input
const int servoPin = 2; // Digital pin for servo output

void setup() {
    myservo.attach(servoPin); 
}
 
void loop() { 
    servo.write(map(analogRead(joystickPin), 0, 1023, 0, 179));       
    delay(15);                     // waits for the servo to get there 
}