Samuel Mokrani
/
USBHostKeyboard_HelloWorld
USBHostKeyboard Hello World
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "USBHostKeyboard.h" 00003 00004 DigitalOut led(LED1); 00005 00006 void onKey(uint8_t key) { 00007 printf("Key: %c\r\n", key); 00008 } 00009 00010 void keyboard_task(void const *) { 00011 00012 USBHostKeyboard keyboard; 00013 00014 while(1) { 00015 // try to connect a USB keyboard 00016 while(!keyboard.connect()) 00017 Thread::wait(500); 00018 00019 // when connected, attach handler called on keyboard event 00020 keyboard.attach(onKey); 00021 00022 // wait until the keyboard is disconnected 00023 while(keyboard.connected()) 00024 Thread::wait(500); 00025 } 00026 } 00027 00028 int main() { 00029 Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4); 00030 while(1) { 00031 led=!led; 00032 Thread::wait(500); 00033 } 00034 }
Generated on Tue Jul 12 2022 15:43:42 by 1.7.2