USB Keyboard with one button

Dependencies:   USBDevice mbed

Committer:
yihui
Date:
Wed Dec 04 07:39:22 2013 +0000
Revision:
0:9692f894c2b7
USB Keyboard with one button

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:9692f894c2b7 1 #include "mbed.h"
yihui 0:9692f894c2b7 2 #include "USBKeyboard.h"
yihui 0:9692f894c2b7 3
yihui 0:9692f894c2b7 4 //LED1: NUM_LOCK, LED2: CAPS_LOCK, LED3: SCROLL_LOCK
yihui 0:9692f894c2b7 5 BusOut leds(LED1, LED2, LED3);
yihui 0:9692f894c2b7 6 DigitalOut button(P1_14); // Configure P1_14 pin as input
yihui 0:9692f894c2b7 7 USBKeyboard keyboard;
yihui 0:9692f894c2b7 8
yihui 0:9692f894c2b7 9 int main() {
yihui 0:9692f894c2b7 10 int buttonPressedCount = 0;
yihui 0:9692f894c2b7 11
yihui 0:9692f894c2b7 12 while (!keyboard.configured()) { // wait until keyboard is configured
yihui 0:9692f894c2b7 13 }
yihui 0:9692f894c2b7 14
yihui 0:9692f894c2b7 15 while (1) {
yihui 0:9692f894c2b7 16 leds = keyboard.lockStatus();
yihui 0:9692f894c2b7 17
yihui 0:9692f894c2b7 18 if (button.read()) {
yihui 0:9692f894c2b7 19 buttonPressedCount++;
yihui 0:9692f894c2b7 20 if (2 == buttonPressedCount) { // when button is pressed about 0.02s
yihui 0:9692f894c2b7 21 keyboard.mediaControl(KEY_MUTE); // send mute key
yihui 0:9692f894c2b7 22 }
yihui 0:9692f894c2b7 23 } else {
yihui 0:9692f894c2b7 24 buttonPressedCount = 0;
yihui 0:9692f894c2b7 25 }
yihui 0:9692f894c2b7 26 wait(0.01);
yihui 0:9692f894c2b7 27 }
yihui 0:9692f894c2b7 28 }