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);
}