Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXOS8700CQ SDFileSystem mbed
Fork of AVC_Robot_Controled_Navigation by
Diff: my_libraries/magnometer.cpp
- Revision:
- 2:94059cb643be
- Parent:
- 1:ab09b233da7b
- Child:
- 4:c60636c95b80
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/my_libraries/magnometer.cpp Thu Oct 16 17:30:52 2014 +0000
@@ -0,0 +1,48 @@
+// ----- Libraries ------------------------------------------------------------------
+#include "mbed.h"
+#include "FXOS8700CQ.h"
+#include "magnometer.h"
+
+// ----- I/O Pins -------------------------------------------------------------------
+FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1)
+
+// ----- Others ---------------------------------------------------------------------
+SRAWDATA accel_data;
+SRAWDATA magn_data;
+
+// ----- Variables ------------------------------------------------------------------
+double mag_x, mag_y;
+double avg_x, avg_y;
+//double average;
+
+// ----- Functions ------------------------------------------------------------------
+double get_mag_x(){
+ fxos.get_data(&accel_data, &magn_data);
+ return magn_data.x;
+}
+
+double get_mag_y(){
+ fxos.get_data(&accel_data, &magn_data);
+ return magn_data.y;
+}
+
+double get_mag_angle(){
+ double _angle;
+ int16_t _x=0;
+ int16_t _y=0;
+
+ for (int i = 0; i < 10; i++){
+ fxos.get_data(&accel_data, &magn_data);
+ avg_x += magn_data.x;
+ avg_y += magn_data.y;
+ //pc.printf("X: %d \tY: %d\r\n", magn_data.x, magn_data.y);
+ //pc.printf("%d\n", magn_data.x);
+ }
+
+ avg_x = avg_x / 10;
+ avg_y = avg_y / 10;
+
+ //pc.printf("%d\n", avg_x);
+ _angle = atan2((double)_x, (double)_y) * 180.0 / 3.14159;
+ return _angle;
+}
\ No newline at end of file
