István Cserny
/
Lab10_USB_keyboard
USBKeyboard "Hello world" example (LEDs setting removed as we don't have LEDs)
main.cpp@0:060ef37bda98, 2022-06-16 (annotated)
- Committer:
- cspista
- Date:
- Thu Jun 16 12:55:34 2022 +0000
- Revision:
- 0:060ef37bda98
Final version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cspista | 0:060ef37bda98 | 1 | |
cspista | 0:060ef37bda98 | 2 | /* USBKeyboard example |
cspista | 0:060ef37bda98 | 3 | * This program will emulate a keyboard and emits few keycodes |
cspista | 0:060ef37bda98 | 4 | * each time when the B1 user button was pressed. |
cspista | 0:060ef37bda98 | 5 | * |
cspista | 0:060ef37bda98 | 6 | * Tested on NUCLEO-F446RE board with Mbed 2 |
cspista | 0:060ef37bda98 | 7 | */ |
cspista | 0:060ef37bda98 | 8 | #include "mbed.h" |
cspista | 0:060ef37bda98 | 9 | #include "USBKeyboard.h" |
cspista | 0:060ef37bda98 | 10 | |
cspista | 0:060ef37bda98 | 11 | DigitalIn SW1(BUTTON1,PullUp); |
cspista | 0:060ef37bda98 | 12 | USBKeyboard keyboard; |
cspista | 0:060ef37bda98 | 13 | |
cspista | 0:060ef37bda98 | 14 | int main(void) |
cspista | 0:060ef37bda98 | 15 | { |
cspista | 0:060ef37bda98 | 16 | while (1) { |
cspista | 0:060ef37bda98 | 17 | while(SW1==1) {} |
cspista | 0:060ef37bda98 | 18 | keyboard.mediaControl(KEY_VOLUME_DOWN); |
cspista | 0:060ef37bda98 | 19 | keyboard.printf("Hello World from Mbed USBKeyboard demo\r\n"); |
cspista | 0:060ef37bda98 | 20 | keyboard.keyCode('s', KEY_CTRL); |
cspista | 0:060ef37bda98 | 21 | keyboard.keyCode(KEY_CAPS_LOCK); |
cspista | 0:060ef37bda98 | 22 | wait(0.02); |
cspista | 0:060ef37bda98 | 23 | while(SW1==0) {} |
cspista | 0:060ef37bda98 | 24 | wait(0.02); |
cspista | 0:060ef37bda98 | 25 | } |
cspista | 0:060ef37bda98 | 26 | } |