Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: KL46Z-USBHost mbed-rtos mbed
Fork of USBHostKeyboard_HelloWorld by
Diff: main.cpp
- Revision:
- 0:88d52e197201
- Child:
- 1:2063e3713a99
diff -r 000000000000 -r 88d52e197201 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Mar 06 17:05:32 2013 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "USBHostKeyboard.h"
+
+DigitalOut led(LED1);
+
+void onKey(uint8_t key) {
+ printf("%c\r\n", key);
+}
+
+void keyboard_task(void const *) {
+
+ USBHostKeyboard keyboard;
+
+ while(1) {
+ // try to connect a USB keyboard
+ while(!keyboard.connect())
+ Thread::wait(500);
+
+ // when connected, attach handler called on keyboard event
+ keyboard.attach(onKey);
+
+ // wait until the keyboard is disconnected
+ while(keyboard.connected())
+ Thread::wait(500);
+ }
+}
+
+int main() {
+ Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
+ while(1) {
+ led=!led;
+ Thread::wait(500);
+ }
+}
