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: MMA8451QASD USBDeviceASD mbed
Fork of FTF2014_lab3_part2 by
Diff: main.cpp
- Revision:
- 4:7ec5c7e1e80f
- Parent:
- 0:61fed686b4a2
- Child:
- 5:303bc488a04a
--- a/main.cpp Mon Apr 07 19:17:09 2014 +0000
+++ b/main.cpp Thu Aug 07 08:37:32 2014 +0000
@@ -1,15 +1,34 @@
+#include "MMA8451Q.h"
#include "mbed.h"
#include "USBMouseKeyboard.h"
-DigitalOut led(LED1);
-USBMouseKeyboard key_mouse;
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+USBMouse joystick;
+AnalogIn ainX(PTB0);
+AnalogIn ainY(PTB1);
int main(void) {
+ int x, y;
+
while (true) {
- key_mouse.printf("hello world from frdm-k64f. \n");
- key_mouse.move(20, 0);
- wait(1);
- key_mouse.keyCode(KEY_CAPS_LOCK);
- led = ((key_mouse.lockStatus() & 0x2) >> 1); /* second bit is caps lock */
+
+ // IF you are using the built-in acceleration sensor of the FRDM-KL25Z, uncomment this part
+/*
+ x = (acc.getAccXX() + 4096)/32;
+ y = (acc.getAccYY() + 4096)/32;
+ x = x + 128;
+ y = y + 128;
+*/
+
+ // IF you are using the analog input of the FRDM-KL25Z, uncomment this part
+ x = ainX.read() * 256;
+ y = ainY.read() * 256;
+ x = x + 128;
+ y = y + 128;
+
+ joystick.move(x, y);
+ wait(0.1);
}
}
