bruce chan
/
send_online
USB keyboard
Revision 0:429b3e5d547d, committed 2017-11-06
- Comitter:
- bruce_0205
- Date:
- Mon Nov 06 08:26:12 2017 +0000
- Commit message:
- keyboard
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Mon Nov 06 08:26:12 2017 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/mbed_official/code/USBDevice/#53949e6131f6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 06 08:26:12 2017 +0000 @@ -0,0 +1,41 @@ +#include "mbed.h" +#include "USBKeyboard.h" + +//LED1: NUM_LOCK, LED2: CAPS_LOCK, LED3: SCROLL_LOCK +BusOut leds(LED1, LED2, LED3); +DigitalIn button_SW2(PTC1); // Configure SW2 pin as input +DigitalIn button_SW3(PTB17); // Configure SW3 pin as input +#define SW2_printf 'S' // set SW2 button input key +#define SW3_printf 'D' // set SW2 button input key +USBKeyboard keyboard; + +int main() { + int buttonPressedCount_SW2 = 0; + int buttonPressedCount_SW3 = 0; + + while (!keyboard.configured()) { // wait until keyboard is configured + } + + while (1) { + leds = keyboard.lockStatus(); + + if (button_SW2.read()) { + buttonPressedCount_SW2++; + if (2 == buttonPressedCount_SW2) { // when button is pressed about 0.02s + keyboard._putc(SW2_printf); // send SW2 key + } + } else { + buttonPressedCount_SW2 = 0; + } + + if (button_SW3.read()) { + buttonPressedCount_SW3++; + if (2 == buttonPressedCount_SW3) { // when button is pressed about 0.02s + keyboard._putc(SW3_printf); // send SW3 key + } + } else { + buttonPressedCount_SW3 = 0; + } + wait(0.01); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Nov 06 08:26:12 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/fb8e0ae1cceb \ No newline at end of file