explanation code


hey,

i found code on internet read mpu6050 x-axis.
i have modified code led burn when there angle.
now don't understand code please explain it?

code: [select]
#include <wire.h>
#include<i2cdev.h>
#include<mpu6050.h>
 
mpu6050 mpu;
 
int16_t ax, ay, az;
int16_t gx, gy, gz;
 
int led = 8;
 
void setup(){
 serial.begin(9600);
 serial.println("initialize mpu");
 mpu.initialize();
 
}
 
void loop(){
 mpu.getmotion6(&ax, &ay, &az, &gx, &gy, &gz);
 
 ax = map(ax, -17000, 17000, -1500, 1500);
 
serial.println(ax);

if(ax>300&& ax<400)
{
  analogwrite(led, 255);
}
else{
  digitalwrite(led, low);
}

}

code: [select]
#include <wire.h>      //include required libraries
#include<i2cdev.h>
#include<mpu6050.h>

mpu6050 mpu;            //create instance of mpu6050 named mpu
int16_t ax, ay, az;     //declare 6 16 bit integer variables
int16_t gx, gy, gz;
int led = 8;            //give led pin name

void setup()
{
  serial.begin(9600);
  serial.println("initialize mpu");
  mpu.initialize();      //initialise sensor
}

void loop()
{
  mpu.getmotion6(&ax, &ay, &az, &gx, &gy, &gz);  //read 6 values 6 variables
  ax = map(ax, -17000, 17000, -1500, 1500);      change range of ax value -17000/17000 -1500/1500
  serial.println(ax);
  if (ax > 300 && ax < 400)  //if ax value between 301 aand 399
  {
    analogwrite(led, 255);    //turn on led (an odd way it, work)
  }
  else {
    digitalwrite(led, low);   //otherwise turn off (an odd way it, work)
  }
}


Arduino Forum > Using Arduino > Programming Questions > explanation code


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code