![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test module for fibo
Fork of ReadingMag_HMC5883L by
main.cpp
- Committer:
- masterholy
- Date:
- 2015-03-02
- Revision:
- 1:ed9abb368fcf
- Parent:
- 0:6bc5f85ca6fa
File content as of revision 1:ed9abb368fcf:
#include "mbed.h" #include "HMC5883L.h" #include "ms5611.h" #include <math.h> #define SDA PB_9 #define SCL PB_8 #define PI 3.14159265 int main() { float x, y, z, heading; float p; /* float m_x, m_y, m_z; */ printf("Inicializing...\r\n"); HMC5883L hmc5883l(SDA, SCL); ms5611 baro(SDA, SCL); baro.cmd_reset(); //HMC5883L *hmc5883l = new HMC5883L(SDA, SCL); printf("OK...\r\n"); /* for (int i = 0 ; i < 100 ; i++) { x += hmc5883l.getMx()/100; y += hmc5883l.getMy()/100; z += hmc5883l.getMz()/100; wait_ms(100); } m_x = x/2; m_y = y/2; m_z = z/2; */ wait(1); while(1) { /* x = m_x - hmc5883l.getMx()*0.92; y = m_y - hmc5883l.getMy()*0.92; z = m_z - hmc5883l.getMz()*0.92; */ x = hmc5883l.getMx(); y = hmc5883l.getMy(); z = hmc5883l.getMz(); p = baro.getPressure(); heading = atan2(y, x); if(heading < 0) heading += 2*PI; if(heading > 2*PI) heading -= 2*PI; heading = heading * 180 / PI; // Correct for when signs are reversed. //if(heading < 0) // heading += 2*PI; //if(heading > 2*PI) // heading -= 2*PI; //while(heading < 0) heading += 360; //while(heading > 360) heading -= 360; printf("x: %f \t\ty: %f \t\t z: %f \t\t heading: %f \t\r\n", x, y, z, heading); printf("pressure : %f \n",p); wait_ms(200); } }