Im trying to make it so when the mpu6050 tilts past a certain threshold, it'll turn on the LED that I have plugged in to pin 7, but after awhile of trying I cant get it to do anything at all
#include <MPU6050.h>
#include <Wire.h>
const int ledPin = 7; //pin number for 3x LEDS
MPU6050 mpu;
void setup() {
pinMode(7, OUTPUT);
Serial.begin(115200);
Wire.begin();
mpu.initialize(); //initializes the mpu... duh
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(7, HIGH);
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
float accelX = ax / 16384.0; //} VVVVV
float accelY = ay / 16384.0; //} Converts the raw values to readable/more understandable ones
Serial.print("X-axis=");
Serial.println(accelX); //prints the X axis on the mpu
Serial.print("Y-axis=");
Serial.println(accelY); //prints the Y axis on the mpu
if(accelX < 0.5) {
digitalWrite(ledPin, HIGH);
} else{
digitalWrite(ledPin, LOW);
}
delay(50);
}