Page 53 - MDP2022-2
P. 53

//  enable  Arduino  interrupt  detection
                            Serial.print(F("Enabling  interrupt  detection  (Arduino  external  interrupt  "));
                            Serial.print(digitalPinToInterrupt(INTERRUPT_PIN));
                            Serial.println(F(")..."));
                            attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN),  dmpDataReady,  RISING);
                            mpuIntStatus  =  mpu.getIntStatus();


                            //  set  our  DMP  Ready  flag  so  the  main  loop()  function  knows  it's  okay  to  use  it
                            Serial.println(F("DMP  ready!  Waiting  for  first  interrupt..."));
                            dmpReady  =  true;

                            //  get  expected  DMP  packet  size  for  later  comparison
                            packetSize  =  mpu.dmpGetFIFOPacketSize();
                    }  else  {
                            //  ERROR!
                            //  1  =  initial  memory  load  failed
                            //  2  =  DMP  configuration  updates  failed
                            //  (if  it's  going  to  break,  usually  the  code  will  be  1)
                            Serial.print(F("DMP  Initialization  failed  (code  "));
                            Serial.print(devStatus);
                            Serial.println(F(")"));
                    }

                    //  configure  LED  for  output
                    pinMode(LED_PIN,  OUTPUT);
                    pinMode(INTERRUPT,  INPUT);                    //  MPU6050  센서  INT핀모드  설정
                    pinMode(5,OUTPUT);
                    pinMode(6,OUTPUT);
                    digitalWrite(5,1);
            }

            //메인  프로그램  loop

            void  loop()  {
                    //  if  programming  failed,  don't  try  to  do  anything
                    if  (!dmpReady)  return;
                    //  read  a  packet  from  FIFO
                    if  (mpu.dmpGetCurrentFIFOPacket(fifoBuffer))  {  //  Get  the  Latest  packet
                            #ifdef  OUTPUT_READABLE_QUATERNION
                                    //  display  quaternion  values  in  easy  matrix  form:  w  x  y  z
                                    mpu.dmpGetQuaternion(&q,  fifoBuffer);
                                    Serial.print("quat\t");
                                    Serial.print(q.w);
                                    Serial.print("\t");
                                    Serial.print(q.x);
                                    Serial.print("\t");
                                    Serial.print(q.y);
                                    Serial.print("\t");
                                    Serial.println(q.z);
                            #endif

                            #ifdef  OUTPUT_READABLE_EULER
                                    //  display  Euler  angles  in  degrees
                                    mpu.dmpGetQuaternion(&q,  fifoBuffer);
                                    mpu.dmpGetEuler(euler,  &q);
   48   49   50   51   52   53   54   55   56   57   58