Yihui Xiong
/
Arch_USB_Keyboard_Ex1
USB Keyboard with one button
Diff: main.cpp
- Revision:
- 0:9692f894c2b7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Dec 04 07:39:22 2013 +0000 @@ -0,0 +1,28 @@ +#include "mbed.h" +#include "USBKeyboard.h" + +//LED1: NUM_LOCK, LED2: CAPS_LOCK, LED3: SCROLL_LOCK +BusOut leds(LED1, LED2, LED3); +DigitalOut button(P1_14); // Configure P1_14 pin as input +USBKeyboard keyboard; + +int main() { + int buttonPressedCount = 0; + + while (!keyboard.configured()) { // wait until keyboard is configured + } + + while (1) { + leds = keyboard.lockStatus(); + + if (button.read()) { + buttonPressedCount++; + if (2 == buttonPressedCount) { // when button is pressed about 0.02s + keyboard.mediaControl(KEY_MUTE); // send mute key + } + } else { + buttonPressedCount = 0; + } + wait(0.01); + } +}