15 #include "simpletools.h" 16 #include "compass3d.h" 17 #include "simplei2c.h" 26 i2c *bus = i2c_newbus(3, 2, 0);
30 i2c *bus2 = i2c_newbus(5, 4, 0);
39 compass_read(bus, &x, &y, &z);
51 float heading = atan2(x, y);
54 heading += 2.0 * 3.14;
57 float headingDegrees = heading * 180/3.14;
59 print(
"\nx=%d, y=%d, z=%d%c\n",
61 print(
"heading = %f, \n",
63 waitcnt(CLKFREQ/2+CNT);
66 compass_read(bus2, &x, &y, &z);
76 heading = atan2(x, y);
79 heading += 2.0 * 3.14;
82 headingDegrees = heading * 180/3.14;
84 print(
"\nx=%d, y=%d, z=%d%c\n",
86 print(
"heading = %f, \n",