USB keyboard

Dependencies:   USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
bruce_0205
Date:
Mon Nov 06 08:26:12 2017 +0000
Commit message:
keyboard

Changed in this revision

USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 429b3e5d547d USBDevice.lib
--- /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
diff -r 000000000000 -r 429b3e5d547d main.cpp
--- /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
diff -r 000000000000 -r 429b3e5d547d mbed.bld
--- /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