#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
int L1 = 13;
int L2 = 12;
int L3= 11;
int L4 = 10;
int L5 = 9;
int L6 = 8;
int L7 = 7;
int L8 = 6;
int L9 = 5;
int L10 = 4;
int L11 = 3;
int L12 = 2;
int L13 = A0;
int L14 = A1;
int L15 = A2;
int Mpu;
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
// set accelerometer range to +-8G
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
// set gyro range to +- 500 deg/s
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
// set filter bandwidth to 21 Hz
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
delay(100);
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
pinMode(L5, OUTPUT);
pinMode(L6, OUTPUT);
pinMode(L7, OUTPUT);
pinMode(L8, OUTPUT);
pinMode(L9, OUTPUT);
pinMode(L10, OUTPUT);
pinMode(L11, OUTPUT);
pinMode(L12, OUTPUT);
pinMode(L13, OUTPUT);
pinMode(L14, OUTPUT);
pinMode(L15, OUTPUT);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
if(a.acceleration.y<=-6.00 && a.acceleration.y>-7.00 ){
digitalWrite(L1,HIGH);
}
else
{
digitalWrite(L1,LOW);
}
if(a.acceleration.y<=-5.00 &&a.acceleration.y>-6.00 ){
digitalWrite(L2,HIGH);
}else
{
digitalWrite(L2,LOW);
}
if(a.acceleration.y<=-4.00&&a.acceleration.y>-5.00 ){
digitalWrite(L3,HIGH);
}else
{
digitalWrite(L3,LOW);
}
if(a.acceleration.y<=-3.00&&a.acceleration.y>-4.00 ){
digitalWrite(L4,HIGH);
}else
{
digitalWrite(L4,LOW);
}
if(a.acceleration.y<=-2.00&&a.acceleration.y>-3.00 ){
digitalWrite(L5,HIGH);
}else
{
digitalWrite(L5,LOW);
}
if(a.acceleration.y<=-1.00&&a.acceleration.y>-2.00 ){
digitalWrite(L6,HIGH);
}else{
digitalWrite(L6,LOW);
}
if(a.acceleration.y<0.00&&a.acceleration.y>-1.00 ){
digitalWrite(L7,HIGH);
}else{
digitalWrite(L7,LOW);
}
if(a.acceleration.y==0 ){
digitalWrite(L8,HIGH);
}else{
digitalWrite(L8,LOW);
}
if(a.acceleration.y<=1.00 && a.acceleration.y>0.01 ){
digitalWrite(L9,HIGH);
}
else
{
digitalWrite(L9,LOW);
}
if(a.acceleration.y<=2.00 &&a.acceleration.y>1.00 ){
digitalWrite(L10,HIGH);
}else
{
digitalWrite(L10,LOW);
}
if(a.acceleration.y<=3.00&&a.acceleration.y>2.00 ){
digitalWrite(L11,HIGH);
}else
{
digitalWrite(L11,LOW);
}
if(a.acceleration.y<=4.00&&a.acceleration.y>3.00 ){
digitalWrite(L12,HIGH);
}else
{
digitalWrite(L12,LOW);
}
if(a.acceleration.y<=5.00&&a.acceleration.y>4.00 ){
digitalWrite(L13,HIGH);
}else
{
digitalWrite(L13,LOW);
}
if(a.acceleration.y<=6.00&&a.acceleration.y>5.00 ){
digitalWrite(L14,HIGH);
}else
{
digitalWrite(L14,LOW);
}
if(a.acceleration.y<=7.00&&a.acceleration.y>6.00 ){
digitalWrite(L15,HIGH);
}else{
digitalWrite(L15,LOW);
}
}
Comments
Please log in or sign up to comment.