Configuração Acelerômetro no Arduíno mpu6050 contagem 0 a 10
Por: Lidieisa • 27/9/2018 • 1.932 Palavras (8 Páginas) • 347 Visualizações
...
Serial.println(F(")"));
}
pinMode(LED_PIN, OUTPUT);
}
void loop() {
if (!dmpReady) return;
while (!mpuInterrupt && fifoCount < packetSize) {
}
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
fifoCount = mpu.getFIFOCount();
if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
}
else if (mpuIntStatus & 0x02) {
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
mpu.getFIFOBytes(fifoBuffer, packetSize);
fifoCount -= packetSize;
#ifdef OUTPUT_READABLE_QUATERNION
mpu.dmpGetQuaternion(&q, fifoBuffer);
Serial.print("quat\t");
Serial.print(q.w);
Serial.print("\t");
Serial.print(q.x);
Serial.print("\t");
#endif
#ifdef OUTPUT_READABLE_EULER
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetEuler(euler, &q);
Serial.print("euler\t");
Serial.print(euler[0] * 180/M_PI);
Serial.print("\t");
Serial.print(euler[1] * 180/M_PI);
Serial.print("\t");
Serial.println(euler[2] * 180/M_PI);
#endif
#ifdef OUTPUT_READABLE_YAWPITCHROLL
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
if( abs (ypr[0] * 20/M_PI) <=2){
nivel = 0;
}
else if(abs (ypr[0] * 20/M_PI) <=3 ) {
nivel=1;
}
else if(abs (ypr[0] * 20/M_PI) <=5 ) {
nivel=2;
}
else if(abs (ypr[0] * 20/M_PI) <=6 ) {
nivel=3;
}
else if(abs (ypr[0] * 20/M_PI) <=8 ) {
nivel=4;
}
else if(abs (ypr[0] * 20/M_PI) <=10 ) {
nivel=5;
}
else if(abs (ypr[0] * 20/M_PI) <=12 ) {
nivel=6;
}
else if(abs (ypr[0] * 20/M_PI) <=14 ) {
nivel=7;
}
else if(abs (ypr[0] * 20/M_PI) <=16 ) {
nivel=8;
}
else if(abs (ypr[0] * 20/M_PI) <=18 ) {
nivel=9;
}
else if(abs (ypr[0] * 20/M_PI) <=20 ) {
nivel=10;
}
//Serial.print("ypr\t");
//Serial.print(ypr[0] * 20/M_PI);
Serial.print(nivel);
Serial.print("\t");
#endif
#ifdef OUTPUT_READABLE_REALACCEL
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
Serial.print("areal\t");
...