Arduino code 1

From Control Systems Technology Group
Revision as of 13:54, 28 March 2020 by H.e.h.hanegraaf@student.tue.nl (talk | contribs) (Created page with ' <pre> #include <Wire.h> #include <MPU6050.h> #include <Servo.h> Servo sg90_x; Servo sg90_y; int servo_x = 2; int servo_y = 10; MPU6050 sensor ; int16_t ax, ay, az ; int16_t gx…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#include <Wire.h>
#include <MPU6050.h>
#include <Servo.h>

Servo sg90_x;
Servo sg90_y;

int servo_x = 2;
int servo_y = 10;
MPU6050 sensor ;
int16_t ax, ay, az ;
int16_t gx, gy, gz ;

double Setpoint;

void setup ( )
{
  Setpoint = 90;
  sg90_x.attach (servo_x);
  sg90_y.attach (servo_y);
  sg90_x.write(Setpoint);
  sg90_y.write(Setpoint);
  Wire.begin( );
  Serial.begin  (9600);

//  Serial.println  ( "Initializing the sensor" );
  sensor.initialize ( );
  Serial.println (sensor.testConnection ( ) ? "Successfully Connected" : "Connection failed");
  delay (100);
}

void loop ( )

{
  sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);
  servo_x = map (ax, -17000, 17000, 0, 255) ;
  servo_y = map(ay, -17000, 17000, 0, 255);


sg90_x.write(x_out);
sg90_y.write(y_out);