2 Servos on each Roll and Pitch axis

I am trying to make 4 servos rotate, 2 on each the roll and pitch axis. On each axis I would like for one servo to rotate clockwise and one to rotate counterclockwise. As of now I can get both servos to rotate in the same direction. Any ideas on how to get them to rotate in opposite directions?

#include <Wire.h>

#include <MPU6050.h>

#include <Servo.h>   

Servo sg90; 
Servo sg91;
Servo sg92;
Servo sg93;       

int servo_pin0 = 8;
int servo_pin1 = 9;
int servo_pin2 = 10;
int servo_pin3 = 11;

MPU6050 sensor ;

int16_t ax, ay, az ;

int16_t gx, gy, gz ;

void setup ( )

{

sg90.attach ( servo_pin0 );
sg91.attach ( servo_pin1 );
sg92.attach ( servo_pin2 );
sg93.attach ( servo_pin3 );

Wire.begin ( );

Serial.begin  (9600);

Serial.println  ( "Initializing the sensor" );

sensor.initialize ( );

Serial.println (sensor.testConnection ( ) ? "Successfully Connected" : "Connection failed");

delay (1000);

Serial.println ( "Taking Values from the sensor" );

delay (1000);

}




void loop ( )

{

sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);

ax = map (ax, -17000, 17000, 0, 180) ;
ay = map (ay, -17000, 17000, 0, 180) ;


Serial.println (ax);
Serial.println (ay);

void reverse() {
sg90.write (ax);
}

sg91.write (ax);

sg92.write (ay);

sg93.write (ay);

delay (000);

}

You will need to send different commands to two servos that are to rotate in opposite directions.

I am aware of that but I don't know how to do that. I am new at programming and have very little knowledge of how to do this.

Have you read up on the nature of the commands that you are currently sending to the servos?

I'll bet that would lead to some quick insight!

I have done googling on how to rotate directions of servos but couldn't find anything related to arduino programming. I was hoping someone on here could give me a quick answer, guess I will keep researching.

Servos are moved to positions not really in directions. Since one end of the travel is at 0 and the other end is at 180 the effective "opposite" of write(0) will be write(180). For any other angle say write(ax) the opposite will be write(180-ax).

Since I don't know what your servos are controlling that's about as near as I can get to "rotate in opposite directions". See if it does what you want.

Steve

Ok, I will try that out. Thanks for your help!

This worked. Thank you for your help