Arduino code 1: Difference between revisions
Jump to navigation
Jump to search
(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…') |
No edit summary |
||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
#include <Wire.h> | #include <Wire.h> | ||
Line 26: | Line 25: | ||
Serial.begin (9600); | Serial.begin (9600); | ||
Serial.println ( "Initializing the sensor" ); | |||
sensor.initialize ( ); | sensor.initialize ( ); | ||
Serial.println (sensor.testConnection ( ) ? "Successfully Connected" : "Connection failed"); | Serial.println (sensor.testConnection ( ) ? "Successfully Connected" : "Connection failed"); | ||
Line 36: | Line 35: | ||
{ | { | ||
sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz); | sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz); | ||
x_out = map(ax, -17000, 17000, 180, 0); //mapped in reverse order to get a counteractive movement. | |||
y)out = map(ay, -17000, 17000, 180, 0); | |||
Latest revision as of 20:25, 5 April 2020
#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); x_out = map(ax, -17000, 17000, 180, 0); //mapped in reverse order to get a counteractive movement. y)out = map(ay, -17000, 17000, 180, 0); sg90_x.write(x_out); sg90_y.write(y_out);