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.
Fork of physical_mario by
Revision 0:db09a1e101b4, committed 2014-09-29
- Comitter:
- smcqueen
- Date:
- Mon Sep 29 02:46:45 2014 +0000
- Commit message:
- Final physical mario code
Changed in this revision
diff -r 000000000000 -r db09a1e101b4 USBDevice.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Mon Sep 29 02:46:45 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/USBDevice/#5bf05f9b3c7b
diff -r 000000000000 -r db09a1e101b4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 29 02:46:45 2014 +0000 @@ -0,0 +1,108 @@ +#include "mbed.h" +#include "USBKeyboard.h" +#include "USBHID.h" + +USBKeyboard keyboard; +//x y and z accelerometer inputs +AnalogIn z(A0); +AnalogIn y(A1); +AnalogIn x(A2); + +HID_REPORT report; +Timeout endJump; + +bool inJump = false; +bool stopJump = false; + +//sends report to end pressing 'z' for jump +void finishJump(){ + stopJump = true; +} + +int main() { + //report to press and release keys + report.data[0] = 1; + report.data[1] = 0; + report.data[3] = 0; // 'z' + report.data[4] = 0; //left + report.data[5] = 0; //right + report.data[6] = 0; //'x' + report.length = 9; + + int direction = 0; //0 is stationary, 1 is left, 2 is right + int speed = 0; //0 is stationary or walking, 1 is running + + while(1) { + + //stop the jump if the timeout has gone + if(stopJump){ + stopJump = false; + inJump = false; + report.data[3] = 0; + keyboard.send(&report); + } + + //check for a jump + if(y.read() > 0.50 && !inJump) { + inJump = true; + float highesty = 0.50; + + //wait until obtaining highest y to know magnitude of jump + float newy = y.read(); + while(newy > 0.50){ + if (newy > highesty) highesty = newy; + newy = y.read(); + } + + //start regular jump if highest y < 0.6 + if(highesty < 0.6){ + report.data[3] = 0x1D; //'z' + keyboard.send(&report); + endJump.attach(&finishJump, 0.1); + } else { + //start high jump otherwise + report.data[3] = 0x1D; //'z' + keyboard.send(&report); + endJump.attach(&finishJump, 0.8); + } + } + + //check for tilt forward or back + float newx = x.read(); + if(newx > 0.52 && direction != 2){ + //start moving forward + direction = 2; + report.data[4] = 0; + report.data[5] = 0x4F; //right + keyboard.send(&report); + } else if(newx < 0.47 && direction != 1){ + //start moving back + direction = 1; + report.data[4] = 0x50; //left + report.data[5] = 0; + keyboard.send(&report); + } else if((newx < 0.51 && direction == 2) || (newx > 0.48 && direction == 1)){ + //stop movement + direction = 0; + report.data[4] = 0; + report.data[5] = 0; + keyboard.send(&report); + } + + //check if mario is running + if((newx > 0.55 || newx < 0.44) && speed == 0){ + //press x to start running + speed = 1; + report.data[6] = 0x1B; + keyboard.send(&report); + pc.printf("start\n\r"); + } else if (newx > 0.47 && newx < 0.52 && speed == 1){ + //release x to stop running + speed = 0; + report.data[6] = 0; + keyboard.send(&report); + pc.printf("stop\n\r"); + } + + } +} \ No newline at end of file
diff -r 000000000000 -r db09a1e101b4 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 29 02:46:45 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file