A level for the Freescale FRDM-KL05Z. Sensitivity can be adjust by the "<0.95f" If it is on 1, the ground must be flat to see this working. Have fun with a digital DIY Level ;D

Dependencies:   MMA8451Q mbed

Files at this revision

API Documentation at this revision

Comitter:
djmanuel
Date:
Fri Nov 28 14:10:03 2014 +0000
Commit message:
Wasserwage

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r fe9e813155a1 MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Fri Nov 28 14:10:03 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 000000000000 -r fe9e813155a1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 28 14:10:03 2014 +0000
@@ -0,0 +1,32 @@
+#include "mbed.h"
+#include "MMA8451Q.h"
+#if defined (TARGET_KL05Z)
+  PinName const SDA = PTB4;
+  PinName const SCL = PTB3;
+#else
+  #error TARGET NOT DEFINED
+#endif
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+int main(void)
+{
+    MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
+    PwmOut rled(LED1); rled = 1.0f;
+    PwmOut gled(LED2); gled = 1.0f;
+    PwmOut bled(LED3 ); bled = 1.0f;
+  
+        start:     
+        float x, y, z;
+        x = abs(acc.getAccX());
+        y = abs(acc.getAccY());
+        z = abs(acc.getAccZ());
+
+while (x > 0.95f) {rled = 0.0f; wait(0.2);goto start;};
+while (y > 0.95f) {bled = 0.0f; wait(0.2);goto start;};
+while (z > 0.95f) {gled = 0.0f; wait(0.2);goto start;};
+
+rled = 1.0f;
+gled = 1.0f;
+bled = 1.0f;
+goto start;
+}
\ No newline at end of file
diff -r 000000000000 -r fe9e813155a1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 28 14:10:03 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file