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: DebounceIn MMA8451Q USBDevice mbed
Fork of HW3_Game_Controller_v2 by
Revision 1:f7b35d39b137, committed 2015-09-19
- Comitter:
- jessielt
- Date:
- Sat Sep 19 01:03:09 2015 +0000
- Parent:
- 0:1bc96dc5dc31
- Commit message:
- Game controller_v2 091815
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gamecontroller2.cpp Sat Sep 19 01:03:09 2015 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "DebounceIn.h"
+#include "USBKeyboard.h"
+#include "MMA8451Q.h"
+
+PinName const SDA = PTE25;
+PinName const SCL = PTE24;
+#define MMA8451_I2C_ADDRESS (0X1d<<1)
+Serial pc(USBTX, USBRX);
+
+USBKeyboard keyboard;
+
+DigitalOut ledr(LED_RED);
+DigitalOut ledg(LED_GREEN);
+DigitalOut ledb(LED_BLUE);
+
+DebounceIn pb1(D13);
+DebounceIn pb2(D3);
+DebounceIn pb3(D4);
+DebounceIn pb4(D5);
+DebounceIn pb5(D6);
+DebounceIn pb6(D7);
+DebounceIn pb7(D8);
+DebounceIn pbs(D9);
+DebounceIn pbm(D10);
+
+int main()
+{
+int m = 1;
+ledr = 1;
+ledg = 1;
+ledb = 1;
+ // Use internal pullup for pushbutton
+ pb1.mode(PullUp);
+ pb2.mode(PullUp);
+ pb3.mode(PullUp);
+ pb4.mode(PullUp);
+ pb5.mode(PullUp);
+ pb6.mode(PullUp);
+ pb7.mode(PullUp);
+ pbs.mode(PullUp);
+ pbm.mode(PullUp);
+
+ // Delay for initial pullup to take effect
+ wait(.001);
+
+ MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
+
+ float x;
+ float y;
+ float z;
+
+ while(true)
+ {
+ x = acc.getAccX();
+ y = acc.getAccY();
+ z = acc.getAccZ();
+
+
+ //keyboard.printf("X = %1.2f ", x);
+ //keyboard.printf("Y = %1.2f ", y);
+ //keyboard.printf("Z = ", z);
+
+ if (x < -0.35) {keyboard.keyCode(LEFT_ARROW);
+ wait(.2);
+
+ }
+ if (x > 0.35) {keyboard.keyCode(RIGHT_ARROW);
+ wait(.2);
+ }
+ if (pb1==0) {keyboard.keyCode(UP_ARROW); //rotates tiles
+ wait(.2);
+ }
+ if (z < 0.2) {keyboard.keyCode('d'); // drops tile
+ wait(.2);
+ }
+
+ }
+
+}
\ No newline at end of file
--- a/main.cpp Wed Sep 16 00:06:41 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-#include "mbed.h"
-#include "DebounceIn.h"
-#include "USBKeyboard.h"
-#include "MMA8451Q.h"
-
-PinName const SDA = PTE25;
-PinName const SCL = PTE24;
-#define MMA8451_I2C_ADDRESS (0X1d<<1)
-Serial pc(USBTX, USBRX);
-
-USBKeyboard keyboard;
-
-DigitalOut ledr(LED_RED);
-DigitalOut ledg(LED_GREEN);
-DigitalOut ledb(LED_BLUE);
-
-DebounceIn pb1(D2);
-DebounceIn pb2(D3);
-DebounceIn pb3(D4);
-DebounceIn pb4(D5);
-DebounceIn pb5(D6);
-DebounceIn pb6(D7);
-DebounceIn pb7(D8);
-DebounceIn pbs(D9);
-DebounceIn pbm(D10);
-
-int main()
-{
-int m = 1;
-ledr = 1;
-ledg = 1;
-ledb = 1;
- // Use internal pullup for pushbutton
- pb1.mode(PullUp);
- pb2.mode(PullUp);
- pb3.mode(PullUp);
- pb4.mode(PullUp);
- pb5.mode(PullUp);
- pb6.mode(PullUp);
- pb7.mode(PullUp);
- pbs.mode(PullUp);
- pbm.mode(PullUp);
-
- // Delay for initial pullup to take effect
- wait(.001);
-
- MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
-
- float x;
- float y;
- float z;
-
- while(true)
- {
- x = acc.getAccX();
- y = acc.getAccY();
- z = acc.getAccZ();
- keyboard.printf("X = %1.2f ", x);
- keyboard.printf("Y = %1.2f ", y);
- keyboard.printf("Z = %1.2f\n", z);
- wait(0.05f);
- }
-
-}
\ No newline at end of file
--- a/mbed.bld Wed Sep 16 00:06:41 2015 +0000 +++ b/mbed.bld Sat Sep 19 01:03:09 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file
