two servo motors turning the x and y position.
However, the GY-801 does not rotate when the third motor rotate around its axis.
How do I run the third engine on its axis, so when I return in the GY-801 Z-axis.
Arduino Digital SDA 20 = GY-801 SDA
Arduino Digital SCL 21 = GY-801 SCL
Arduino VCC = GY-801 VCC_IN
Arduino GND = GY-801 GND
Servo Motors
Digital 9, 10, 11
Arduino Code
#include <Wire.h>
#include <ADXL345.h>
#include <Servo.h>
Servo servo1; // create servo object to control a servo
Servo servo2;
Servo servo3;
ADXL345 adxl; //variable adxl is an instance of the ADXL345 library
int x, y, z;
int rawX, rawY, rawZ;
int mappedRawX, mappedRawY, mappedRawZ;
void setup() {
Serial.begin(9600);
adxl.powerOn();
servo1.attach(9);
servo2.attach(10);
servo3.attach(11);
}
void loop() {
adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables x,y,z
rawX = x - 7;
rawY = y - 6;
rawZ = z - 10;
if (rawX < -255) rawX = -255; else if (rawX > 255) rawX = 255;
if (rawY < -255) rawY = -255; else if (rawY > 255) rawY = 255;
if (rawZ < -255) rawZ = -255; else if (rawZ > 255) rawZ = 255;
mappedRawX = map(rawX, -255, 255, 0, 180);
mappedRawY = map(rawY, -255, 255, 0, 180);
mappedRawZ = map(rawZ, -255, 255, 0, 180);
servo1.write(mappedRawX);
delay(15);
servo2.write(mappedRawY); //(180 - mappedRawY);
delay(15);
servo3.write(mappedRawZ);
delay(15);
Serial.print(" mappedRawX = "); Serial.print(mappedRawX); // raw data with offset
Serial.print(" mappedRawY = "); Serial.println(mappedRawY); // raw data with offset
Serial.print(" mappedRawZ = "); Serial.println(mappedRawZ); // raw data with offset
}