USB Keyboard with one button

Dependencies:   USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
yihui
Date:
Wed Dec 04 07:39:22 2013 +0000
Commit message:
USB Keyboard with one button

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Wed Dec 04 07:39:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#849c0c0f2769
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 04 07:39:22 2013 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+#include "USBKeyboard.h"
+
+//LED1: NUM_LOCK, LED2: CAPS_LOCK, LED3: SCROLL_LOCK
+BusOut leds(LED1, LED2, LED3);
+DigitalOut button(P1_14);               // Configure P1_14 pin as input
+USBKeyboard keyboard;
+
+int main() {
+    int buttonPressedCount = 0; 
+    
+    while (!keyboard.configured()) {    // wait until keyboard is configured
+    }
+    
+    while (1) {
+        leds = keyboard.lockStatus();
+        
+        if (button.read()) {
+            buttonPressedCount++;
+            if (2 == buttonPressedCount) { // when button is pressed about 0.02s
+                keyboard.mediaControl(KEY_MUTE); // send mute key
+            }
+        } else {
+            buttonPressedCount = 0;
+        }
+        wait(0.01);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 04 07:39:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file