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.
Diff: main.cpp
- Revision:
- 0:a1caba5c4e48
- Child:
- 2:fcf30b3e1c14
diff -r 000000000000 -r a1caba5c4e48 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Feb 08 19:25:08 2017 +0000
@@ -0,0 +1,32 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "MMA8451Q.h"
+
+ PinName const SDA = PTE25;
+ PinName const SCL = PTE24;
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+int main(void)
+{
+ MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
+ PwmOut rled(LED1);
+ PwmOut gled(LED2);
+ PwmOut bled(LED3);
+ Serial pc(USBTX, USBRX); // tx, rx
+
+
+ pc.printf("MMA8451 ID: %d\n", acc.getWhoAmI());
+
+ while (true) {
+ float x, y, z;
+ x = acc.getAccX();
+ y = acc.getAccY();
+ z = acc.getAccZ();
+ rled = 1.0f - abs(x);
+ gled = 1.0f - abs(y);
+ bled = 1.0f - abs(z);
+ Thread::wait(300);
+ pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z);
+ }
+}