USBKeyboard example with media keys

Dependencies:   USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
samux
Date:
Thu Nov 03 17:35:10 2011 +0000
Child:
1:f9120f998887
Commit message:

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Thu Nov 03 17:35:10 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/samux/code/USBDevice/#019ce73594da
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 03 17:35:10 2011 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "USBKeyboard.h"
+
+USBKeyboard keyboard;
+
+//Bus of leds
+BusOut leds(LED1,LED2,LED3,LED4);
+
+//Bus of buttons
+BusInOut buttons(p21, p22, p23, p24, p25, p26, p29);
+
+int main(void) {
+    uint8_t p_bus = 0;
+
+    while (1) {
+        //if the bus of buttons has changed, send a report
+        if (buttons.read() != p_bus) {
+            p_bus = buttons.read();
+            if(p_bus & 0x01)
+               keyboard.mediaControl(KEY_MUTE);
+            if(p_bus & 0x02)
+               keyboard.mediaControl(KEY_VOLUME_DOWN);
+            if(p_bus & 0x04)
+               keyboard.mediaControl(KEY_VOLUME_UP);
+            if(p_bus & 0x08)
+               keyboard.mediaControl(KEY_NEXT_TRACK);
+            if(p_bus & 0x10)
+               keyboard.mediaControl(KEY_PLAY_PAUSE);
+            if(p_bus & 0x20)
+               keyboard.mediaControl(KEY_PREVIOUS_TRACK);
+            if(p_bus & 0x40)
+               keyboard.printf("Hello World\r\n");
+        }
+        wait(0.01);
+    }
+}
+
+