![](/media/cache/profiles/69f65a2e91e6051a23abe7293bf3386a.50x50_q85.jpg)
USBKeyboard example with media keys
main.cpp@0:a39a21b79528, 2011-11-03 (annotated)
- Committer:
- samux
- Date:
- Thu Nov 03 17:35:10 2011 +0000
- Revision:
- 0:a39a21b79528
- Child:
- 1:f9120f998887
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:a39a21b79528 | 1 | #include "mbed.h" |
samux | 0:a39a21b79528 | 2 | #include "USBKeyboard.h" |
samux | 0:a39a21b79528 | 3 | |
samux | 0:a39a21b79528 | 4 | USBKeyboard keyboard; |
samux | 0:a39a21b79528 | 5 | |
samux | 0:a39a21b79528 | 6 | //Bus of leds |
samux | 0:a39a21b79528 | 7 | BusOut leds(LED1,LED2,LED3,LED4); |
samux | 0:a39a21b79528 | 8 | |
samux | 0:a39a21b79528 | 9 | //Bus of buttons |
samux | 0:a39a21b79528 | 10 | BusInOut buttons(p21, p22, p23, p24, p25, p26, p29); |
samux | 0:a39a21b79528 | 11 | |
samux | 0:a39a21b79528 | 12 | int main(void) { |
samux | 0:a39a21b79528 | 13 | uint8_t p_bus = 0; |
samux | 0:a39a21b79528 | 14 | |
samux | 0:a39a21b79528 | 15 | while (1) { |
samux | 0:a39a21b79528 | 16 | //if the bus of buttons has changed, send a report |
samux | 0:a39a21b79528 | 17 | if (buttons.read() != p_bus) { |
samux | 0:a39a21b79528 | 18 | p_bus = buttons.read(); |
samux | 0:a39a21b79528 | 19 | if(p_bus & 0x01) |
samux | 0:a39a21b79528 | 20 | keyboard.mediaControl(KEY_MUTE); |
samux | 0:a39a21b79528 | 21 | if(p_bus & 0x02) |
samux | 0:a39a21b79528 | 22 | keyboard.mediaControl(KEY_VOLUME_DOWN); |
samux | 0:a39a21b79528 | 23 | if(p_bus & 0x04) |
samux | 0:a39a21b79528 | 24 | keyboard.mediaControl(KEY_VOLUME_UP); |
samux | 0:a39a21b79528 | 25 | if(p_bus & 0x08) |
samux | 0:a39a21b79528 | 26 | keyboard.mediaControl(KEY_NEXT_TRACK); |
samux | 0:a39a21b79528 | 27 | if(p_bus & 0x10) |
samux | 0:a39a21b79528 | 28 | keyboard.mediaControl(KEY_PLAY_PAUSE); |
samux | 0:a39a21b79528 | 29 | if(p_bus & 0x20) |
samux | 0:a39a21b79528 | 30 | keyboard.mediaControl(KEY_PREVIOUS_TRACK); |
samux | 0:a39a21b79528 | 31 | if(p_bus & 0x40) |
samux | 0:a39a21b79528 | 32 | keyboard.printf("Hello World\r\n"); |
samux | 0:a39a21b79528 | 33 | } |
samux | 0:a39a21b79528 | 34 | wait(0.01); |
samux | 0:a39a21b79528 | 35 | } |
samux | 0:a39a21b79528 | 36 | } |
samux | 0:a39a21b79528 | 37 | |
samux | 0:a39a21b79528 | 38 |