test

Dependencies:   HCSR04 HMC5883L mbed

main.cpp

Committer:
sedid
Date:
2017-06-09
Revision:
0:85467ac58aa4

File content as of revision 0:85467ac58aa4:

#include "mbed.h"
#include "math.h"
#include <HMC5883L.h>
#include "hcsr04.h"
#define PI 3.14159265359
#define PERIOD 0.0001

//Boussole
HMC5883L toto(p28,p27);

int main()
{
   

    toto.setDefault();
    int Mx,My,Mz;
    float x,y,z;
  
  
 
    while(1) {
        //Boussole
        Mx=toto.getMx();
        My=toto.getMy();
        Mz=toto.getMz();
        if(Mx>32500) Mx=Mx-65535;
        if(My>32500) My=My-65535;
        if(Mz>32500) Mz=Mz-65535;
        x=atan2((float)My,(float)Mx);
        y=atan2((float)Mz,(float)Mx);
        z=atan2((float)Mz,(float)My);
        if(x<0)x+=2*PI;
        if(x>2*PI)x-=2*PI;
        if(y<0)y+=2*PI;
        if(y>2*PI)y-=2*PI;
        if(z<0)z+=2*PI;
        if(z>2*PI)z-=2*PI;
        x=x*180/PI;
        y=y*180/PI;
        z=z*180/PI;
        float error=90-y;
        printf("angle:%d\t %d\t%d\n\r",My,Mx,Mz);
       }
       
       }