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: mbed DebounceIn USBDevice PinDetect
main.cpp
00001 #include "mbed.h" 00002 #include "PinDetect.h" 00003 #include "USBKeyboard.h" 00004 #include "DebounceIn.h" 00005 00006 #define PINDETECT_SAMPLE_FREQUENCY 10000 00007 00008 DigitalOut led(LED_GREEN); 00009 DebounceIn mode(D12); 00010 DebounceIn accelerate(D11); 00011 DebounceIn powerUp(D10); 00012 DebounceIn breakz(D13); 00013 DebounceIn up(D9); 00014 DebounceIn down(D7); 00015 DebounceIn left(D6); 00016 DebounceIn right(D8); 00017 00018 HID_REPORT report; 00019 00020 AnalogIn accelZ(A0); 00021 AnalogIn accelY(A1); 00022 AnalogIn accelX(A2); 00023 00024 //USBMouseKeyboard 00025 USBKeyboard controller; 00026 00027 //X: 0.48 - 0.51 00028 //Z: 0.47 - 0.57 00029 float CENTER_LEFT = 0.48; 00030 float CENTER_RIGHT = 0.51; 00031 float CENTER_UP = 0.47; 00032 float CENTER_DOWN = 0.57; 00033 int flag = 1; // to change modes between directions via 1.buttons or 2.accelerometer 00034 00035 int main(void) { 00036 report.data[0] = 1; 00037 report.length = 9; 00038 while (true) { 00039 if (!mode) { 00040 flag = !flag; 00041 wait(0.5); 00042 } 00043 00044 //KL25Z Debugging Purposes 00045 led=!led; 00046 wait(0.05); 00047 00048 //Mode 1: Accelerometer 00049 if (flag) { 00050 if (!accelerate) { 00051 report.data[3] = 0x1B; //x 00052 } else { 00053 report.data[3] = 0; 00054 } 00055 if (!powerUp) { 00056 report.data[8] = 0x16; //s 00057 } else { 00058 report.data[8] = 0; 00059 } 00060 if (accelX.read() <= CENTER_LEFT) { 00061 report.data[4] = 0x50; 00062 } else { 00063 report.data[4] = 0; 00064 } 00065 if (accelX.read() >= CENTER_RIGHT) { 00066 report.data[5] = 0x4F; 00067 } else { 00068 report.data[5] = 0; 00069 } 00070 if (accelZ.read() <= CENTER_UP) { 00071 report.data[6] = 0x52; 00072 } else if (!breakz) { 00073 report.data[6] = 0x1D; //z 00074 } else { 00075 report.data[6] = 0; 00076 } 00077 if (accelZ.read() >= CENTER_DOWN) { 00078 report.data[7] = 0x51; 00079 } else { 00080 report.data[7] = 0; 00081 } 00082 controller.send(&report); 00083 } 00084 00085 //Mode 2: Buttons 00086 if (!flag) { 00087 if (!accelerate) { 00088 report.data[3] = 0x1B; //x 00089 } else { 00090 report.data[3] = 0; 00091 } 00092 if (!powerUp) { 00093 report.data[8] = 0x16; //s 00094 } else { 00095 report.data[8] = 0; 00096 } 00097 if (!up) { 00098 report.data[4] = 0x52; 00099 } else if (!breakz) { 00100 report.data[4] = 0x1D; //z 00101 } else { 00102 report.data[4] = 0; 00103 } 00104 if (!down) { 00105 report.data[5] = 0x51; 00106 } else { 00107 report.data[5] = 0; 00108 } 00109 if (!left) { 00110 report.data[6] = 0x50; 00111 } else { 00112 report.data[6] = 0; 00113 } 00114 if (!right) { 00115 report.data[7] = 0x4F; 00116 } else { 00117 report.data[7] = 0; 00118 } 00119 controller.send(&report); 00120 } 00121 } 00122 }
Generated on Mon Aug 8 2022 11:40:59 by
1.7.2