Simple example on how to use the application board joystick as input for your pc.
Fork of USBKeyboard_HelloWorld by
Revision 7:6081df4a2680, committed 2016-02-20
- Comitter:
- Perijah
- Date:
- Sat Feb 20 12:03:19 2016 +0000
- Parent:
- 6:17871da2a7e4
- Commit message:
- Keyboard with mbed application board joystick functions
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 17871da2a7e4 -r 6081df4a2680 main.cpp --- a/main.cpp Fri Mar 01 13:23:58 2013 +0000 +++ b/main.cpp Sat Feb 20 12:03:19 2016 +0000 @@ -1,21 +1,33 @@ #include "mbed.h" #include "USBKeyboard.h" - -//LED1: NUM_LOCK -//LED2: CAPS_LOCK -//LED3: SCROLL_LOCK -BusOut leds(LED1, LED2, LED3); - + + +BusOut leds(LED1, LED2, LED3); //Not used +DigitalIn rechts(p16); //Joystick pins on application board +DigitalIn up(p15); +DigitalIn down(p12); +DigitalIn left(p13); + //USBKeyboard -USBKeyboard keyboard; - -int main(void) { +USBKeyboard keyboard; // create keyboard object + +int main(void) +{ while (1) { - keyboard.mediaControl(KEY_VOLUME_DOWN); - keyboard.printf("Hello World from Mbed\r\n"); - keyboard.keyCode('s', KEY_CTRL); - keyboard.keyCode(KEY_CAPS_LOCK); - wait(1); - leds = keyboard.lockStatus(); + //all pins are checked whtether or not they are pressed + if(rechts) { + keyboard.keyCode(RIGHT_ARROW); //send the appropriate key + } + if(up) { + keyboard.keyCode(UP_ARROW); + } + if(down) { + keyboard.keyCode(DOWN_ARROW); + } + if(left) { + keyboard.keyCode(LEFT_ARROW); + } + + leds = keyboard.lockStatus(); //not used } } \ No newline at end of file