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: mbed HCSR04 HMC6352 PID TextLCD
Diff: compass.h
- Revision:
- 1:d0cada9a5381
- Child:
- 2:a8bbf677e774
diff -r 174d34b8177d -r d0cada9a5381 compass.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/compass.h Tue Aug 04 04:13:02 2015 +0000
@@ -0,0 +1,45 @@
+#ifndef COMPASS_H
+#define COMPASS_H
+
+#include "mbed.h"
+#include "HMC6352.h"
+
+class Compass {
+private:
+ float initialAngle;
+ HMC6352* hmc6352;
+
+public:
+ float diffAngle;
+ Compass(PinName sda, PinName scl);
+ void measureAngle(void);
+};
+
+Compass::Compass(PinName sda, PinName scl) {
+ hmc6352 = new HMC6352(sda, scl);
+ hmc6352->setOpMode(HMC6352_CONTINUOUS, 1, 20);
+ wait(0.1);
+ this->initialAngle = hmc6352->sample() / 10.0;
+}
+
+void Compass::measureAngle(void) {
+ wait(0.1);
+ this->diffAngle = hmc6352->sample() / 10.0 - initialAngle;
+}
+
+#endif
+
+/*
+ * example program
+
+#include "mbed.h"
+#include "compass.h"
+
+int main(void) {
+ Compass compass(D14, D15);
+ while (1) {
+ compass.measureAngle();
+ pc.printf("%f\r\n", compass.diffAngle);
+ }
+}
+ */
\ No newline at end of file