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.
main.cpp@1:b1c07ebce303, 2022-06-16 (annotated)
- Committer:
- cspista
- Date:
- Thu Jun 16 13:00:48 2022 +0000
- Revision:
- 1:b1c07ebce303
- Parent:
- 0:a3bde7e2c11e
Final version corrected
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| cspista | 0:a3bde7e2c11e | 1 | |
| cspista | 0:a3bde7e2c11e | 2 | /* USB Keyboard extended example |
| cspista | 0:a3bde7e2c11e | 3 | * This program will emulate an USB keyboard and |
| cspista | 1:b1c07ebce303 | 4 | * emits predefined key sequences when the corresponding |
| cspista | 0:a3bde7e2c11e | 5 | * button was pressed |
| cspista | 0:a3bde7e2c11e | 6 | * |
| cspista | 0:a3bde7e2c11e | 7 | * Tested on NUCLEO-F446RE board with Arduino Multifunction Board using Mbed 2 |
| cspista | 0:a3bde7e2c11e | 8 | */ |
| cspista | 0:a3bde7e2c11e | 9 | #include "mbed.h" |
| cspista | 0:a3bde7e2c11e | 10 | #include "USBKeyboard.h" |
| cspista | 0:a3bde7e2c11e | 11 | |
| cspista | 0:a3bde7e2c11e | 12 | DigitalIn B1(BUTTON1,PullUp); |
| cspista | 0:a3bde7e2c11e | 13 | DigitalIn S1(A1,PullUp); |
| cspista | 0:a3bde7e2c11e | 14 | DigitalIn S2(A2,PullUp); |
| cspista | 0:a3bde7e2c11e | 15 | DigitalIn S3(A3,PullUp); |
| cspista | 0:a3bde7e2c11e | 16 | USBKeyboard keyboard; |
| cspista | 0:a3bde7e2c11e | 17 | |
| cspista | 0:a3bde7e2c11e | 18 | int B1state = 1; |
| cspista | 0:a3bde7e2c11e | 19 | int S1state = 1; |
| cspista | 0:a3bde7e2c11e | 20 | int S2state = 1; |
| cspista | 0:a3bde7e2c11e | 21 | int S3state = 1; |
| cspista | 0:a3bde7e2c11e | 22 | |
| cspista | 0:a3bde7e2c11e | 23 | int main(void) |
| cspista | 0:a3bde7e2c11e | 24 | { |
| cspista | 0:a3bde7e2c11e | 25 | while (1) { |
| cspista | 0:a3bde7e2c11e | 26 | if (B1state && !B1) { |
| cspista | 0:a3bde7e2c11e | 27 | keyboard.mediaControl(KEY_VOLUME_DOWN); |
| cspista | 0:a3bde7e2c11e | 28 | keyboard.printf("Hello World from Mbed USBKeyboard demo\r\n"); |
| cspista | 0:a3bde7e2c11e | 29 | keyboard.keyCode('s', KEY_CTRL); |
| cspista | 0:a3bde7e2c11e | 30 | keyboard.keyCode(KEY_CAPS_LOCK); |
| cspista | 0:a3bde7e2c11e | 31 | B1state = 0; |
| cspista | 0:a3bde7e2c11e | 32 | wait(1); |
| cspista | 0:a3bde7e2c11e | 33 | } else if(!B1state && B1) B1state = 1; |
| cspista | 0:a3bde7e2c11e | 34 | |
| cspista | 0:a3bde7e2c11e | 35 | if (S1state && !S1) { |
| cspista | 0:a3bde7e2c11e | 36 | keyboard.keyCode('r', KEY_LOGO); // Windows kay + R key command |
| cspista | 0:a3bde7e2c11e | 37 | keyboard.printf("https://megtestesules.info\r\n "); |
| cspista | 0:a3bde7e2c11e | 38 | S1state = 0; |
| cspista | 0:a3bde7e2c11e | 39 | wait(1); |
| cspista | 0:a3bde7e2c11e | 40 | } |
| cspista | 0:a3bde7e2c11e | 41 | else if(!S1state && S1) S1state = 1; |
| cspista | 0:a3bde7e2c11e | 42 | |
| cspista | 0:a3bde7e2c11e | 43 | if (S2state && !S2) { |
| cspista | 0:a3bde7e2c11e | 44 | keyboard.keyCode('r', KEY_LOGO); // Windows key + R key command |
| cspista | 0:a3bde7e2c11e | 45 | keyboard.printf("https://megtestesules.info/hobbielektronika/\r\n "); |
| cspista | 0:a3bde7e2c11e | 46 | S2state = 0; |
| cspista | 0:a3bde7e2c11e | 47 | wait(1); |
| cspista | 0:a3bde7e2c11e | 48 | } |
| cspista | 0:a3bde7e2c11e | 49 | else if(!S2state && S2) S2state = 1; |
| cspista | 0:a3bde7e2c11e | 50 | |
| cspista | 0:a3bde7e2c11e | 51 | if (S3state && !S3) { |
| cspista | 0:a3bde7e2c11e | 52 | keyboard.keyCode('r', KEY_LOGO); // Windows key + R key command |
| cspista | 0:a3bde7e2c11e | 53 | keyboard.printf("https://cspista.hu/\r\n "); |
| cspista | 0:a3bde7e2c11e | 54 | S3state = 0; |
| cspista | 0:a3bde7e2c11e | 55 | wait(1); |
| cspista | 0:a3bde7e2c11e | 56 | } |
| cspista | 0:a3bde7e2c11e | 57 | else if(!S3state && S3) S3state = 1; |
| cspista | 0:a3bde7e2c11e | 58 | wait(0.02); |
| cspista | 0:a3bde7e2c11e | 59 | } |
| cspista | 0:a3bde7e2c11e | 60 | } |