USB Keyboard with one button

Dependencies:   USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBKeyboard.h"
00003 
00004 //LED1: NUM_LOCK, LED2: CAPS_LOCK, LED3: SCROLL_LOCK
00005 BusOut leds(LED1, LED2, LED3);
00006 DigitalOut button(P1_14);               // Configure P1_14 pin as input
00007 USBKeyboard keyboard;
00008 
00009 int main() {
00010     int buttonPressedCount = 0; 
00011     
00012     while (!keyboard.configured()) {    // wait until keyboard is configured
00013     }
00014     
00015     while (1) {
00016         leds = keyboard.lockStatus();
00017         
00018         if (button.read()) {
00019             buttonPressedCount++;
00020             if (2 == buttonPressedCount) { // when button is pressed about 0.02s
00021                 keyboard.mediaControl(KEY_MUTE); // send mute key
00022             }
00023         } else {
00024             buttonPressedCount = 0;
00025         }
00026         wait(0.01);
00027     }
00028 }