![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
5 buttons for each hand - chorded keyboard
Dependencies: PinDetect USBDevice mbed
Fork of USBKeyboard_HelloWorld by
Revision 7:05d567c0f879, committed 2015-09-13
- Comitter:
- saurabhmitra
- Date:
- Sun Sep 13 09:03:16 2015 +0000
- Parent:
- 6:17871da2a7e4
- Commit message:
- HW 2 finished
Changed in this revision
PinDetect.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Sun Sep 13 09:03:16 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- a/main.cpp Fri Mar 01 13:23:58 2013 +0000 +++ b/main.cpp Sun Sep 13 09:03:16 2015 +0000 @@ -1,21 +1,73 @@ #include "mbed.h" #include "USBKeyboard.h" - -//LED1: NUM_LOCK -//LED2: CAPS_LOCK -//LED3: SCROLL_LOCK -BusOut leds(LED1, LED2, LED3); - +// #include "DigitalIn.h" + +#define NUM_WAIT 80 +#define DELAY 2 + +BusOut leds( LED1, LED2, LED3, LED4 ); +BusIn pins(D3,D4,D5,D6,D7,D8,D9,D10,D11,D12); + //USBKeyboard USBKeyboard keyboard; - + int main(void) { + leds = 255; + int old_pins = 0; + char count = 0; 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(); + if (old_pins == pins.read()) { +// keyboard.printf("Count: %d\r\n", count); + count++; + } else { + count = 0; + } + old_pins = pins.read(); + if (count >= NUM_WAIT) { +// keyboard.printf("%d\r\n", ~(pins.read())); + old_pins = 0x3ff & (~old_pins); // make sure all other bits are 0 (after the 10 lowest order) + switch(old_pins) { + case 0x000: break; + // Vowels on left hand - one per finger + case 0x001: keyboard.printf("a");break; + case 0x002: keyboard.printf("e");break; + case 0x004: keyboard.printf("i");break; + case 0x008: keyboard.printf("o");break; + case 0x010: keyboard.printf("u");break; + + // Consonants on right hand, different combos + case 0x020: keyboard.printf("t");break; + case 0x040: keyboard.printf("n");break; + case 0x080: keyboard.printf("s");break; + case 0x100: keyboard.printf("h");break; + case 0x200: keyboard.printf("r");break; + case 0x060: keyboard.printf("d");break; + case 0x0A0: keyboard.printf("l");break; + case 0x120: keyboard.printf("c");break; + case 0x220: keyboard.printf("m");break; + case 0x0C0: keyboard.printf("w");break; + case 0x140: keyboard.printf("f");break; + case 0x240: keyboard.printf("g");break; + case 0x180: keyboard.printf("y");break; + case 0x280: keyboard.printf("p");break; + case 0x300: keyboard.printf("b");break; + case 0x0E0: keyboard.printf("v");break; + case 0x160: keyboard.printf("k");break; + case 0x260: keyboard.printf("j");break; + case 0x1a0: keyboard.printf("x");break; + case 0x2a0: keyboard.printf("q");break; + case 0x320: keyboard.printf("z");break; + + // Special Keys + case 0x003: keyboard.printf("\r\n");break; + case 0x005: keyboard.printf(" ");break; + case 0x009: keyboard.keyCode(KEY_CAPS_LOCK);break; + case 0x011: keyboard.printf("\b");break; + + default: + break; + } + } + wait_ms(DELAY); } } \ No newline at end of file