![](/media/cache/profiles/7c39a5f991bef4a1e34187677a65871d.jpg.50x50_q85.jpg)
Jogpad for the Mach3 CNC control software with Maple Mini board (STM32F103CBT6).
Dependencies: mbed mbed-MapleMini USBDevice_STM32F103
main.cpp
00001 #include "MapleMini.h" 00002 #include "mbed.h" 00003 #include "USBKeyboard.h" 00004 00005 #define POS_MIN 20000 00006 #define POS_MAX 50000 00007 00008 DigitalOut led(PB_1); // LED 00009 DigitalOut usbEn(PB_9); // Used for connecting/disconnecting the 1k5 resistor to/from the USB DP pin 00010 AnalogIn vRx(PB_0); // Joystick Rx pin 00011 AnalogIn vRy(PA_7); // Joystick Ry pin 00012 DigitalIn btnCtrl(PB_12, PullDown); // Ctrl key 00013 DigitalIn btnShift(PB_14 , PullDown); // Shift key 00014 DigitalIn btnUp(PA_10, PullDown); // PageUp key (Z-up) 00015 DigitalIn btnDown(PA_1, PullDown); // PageDown key (Z-down) 00016 uint8_t modifier = 0; 00017 USBKeyboard* keyboard; 00018 00019 /** 00020 * @brief 00021 * @note 00022 * @param 00023 * @retval 00024 */ 00025 int main() 00026 { 00027 confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) 00028 led = 1; 00029 keyboard = new USBKeyboard(); 00030 usbEn = 0; //Keep the on-board 1k5 resistor connected to USB DP pin 00031 while (1) { 00032 if (btnShift == 1) { 00033 modifier = KEY_SHIFT; 00034 } 00035 else 00036 if (btnCtrl == 1) { 00037 modifier = KEY_CTRL; 00038 } 00039 else { 00040 modifier = 0; 00041 } 00042 00043 if (vRy.read_u16() < POS_MIN) { 00044 keyboard->keyCode(LEFT_ARROW, modifier, false); 00045 } 00046 else 00047 if (vRy.read_u16() > POS_MAX) { 00048 keyboard->keyCode(RIGHT_ARROW, modifier, false); 00049 } 00050 else 00051 if (vRx.read_u16() < POS_MIN) { 00052 keyboard->keyCode(DOWN_ARROW, modifier, false); 00053 } 00054 else 00055 if (vRx.read_u16() > POS_MAX) { 00056 keyboard->keyCode(UP_ARROW, modifier, false); 00057 } 00058 else 00059 if (btnUp == 1) { 00060 keyboard->keyCode(KEY_PAGE_UP, modifier, false); 00061 } 00062 else 00063 if (btnDown == 1) { 00064 keyboard->keyCode(KEY_PAGE_DOWN, modifier, false); 00065 } 00066 else { 00067 keyboard->keyCode(0, 0); // Release the key(s) 00068 } 00069 } 00070 }
Generated on Wed Jul 13 2022 10:36:11 by
![doxygen](doxygen.png)