![](/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
main.cpp@7:05d567c0f879, 2015-09-13 (annotated)
- Committer:
- saurabhmitra
- Date:
- Sun Sep 13 09:03:16 2015 +0000
- Revision:
- 7:05d567c0f879
- Parent:
- 5:03a4211d593a
HW 2 finished
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:291a88a2c151 | 1 | #include "mbed.h" |
samux | 1:291a88a2c151 | 2 | #include "USBKeyboard.h" |
saurabhmitra | 7:05d567c0f879 | 3 | // #include "DigitalIn.h" |
saurabhmitra | 7:05d567c0f879 | 4 | |
saurabhmitra | 7:05d567c0f879 | 5 | #define NUM_WAIT 80 |
saurabhmitra | 7:05d567c0f879 | 6 | #define DELAY 2 |
saurabhmitra | 7:05d567c0f879 | 7 | |
saurabhmitra | 7:05d567c0f879 | 8 | BusOut leds( LED1, LED2, LED3, LED4 ); |
saurabhmitra | 7:05d567c0f879 | 9 | BusIn pins(D3,D4,D5,D6,D7,D8,D9,D10,D11,D12); |
saurabhmitra | 7:05d567c0f879 | 10 | |
samux | 3:8b56768ceca2 | 11 | //USBKeyboard |
samux | 3:8b56768ceca2 | 12 | USBKeyboard keyboard; |
saurabhmitra | 7:05d567c0f879 | 13 | |
samux | 1:291a88a2c151 | 14 | int main(void) { |
saurabhmitra | 7:05d567c0f879 | 15 | leds = 255; |
saurabhmitra | 7:05d567c0f879 | 16 | int old_pins = 0; |
saurabhmitra | 7:05d567c0f879 | 17 | char count = 0; |
samux | 1:291a88a2c151 | 18 | while (1) { |
saurabhmitra | 7:05d567c0f879 | 19 | if (old_pins == pins.read()) { |
saurabhmitra | 7:05d567c0f879 | 20 | // keyboard.printf("Count: %d\r\n", count); |
saurabhmitra | 7:05d567c0f879 | 21 | count++; |
saurabhmitra | 7:05d567c0f879 | 22 | } else { |
saurabhmitra | 7:05d567c0f879 | 23 | count = 0; |
saurabhmitra | 7:05d567c0f879 | 24 | } |
saurabhmitra | 7:05d567c0f879 | 25 | old_pins = pins.read(); |
saurabhmitra | 7:05d567c0f879 | 26 | if (count >= NUM_WAIT) { |
saurabhmitra | 7:05d567c0f879 | 27 | // keyboard.printf("%d\r\n", ~(pins.read())); |
saurabhmitra | 7:05d567c0f879 | 28 | old_pins = 0x3ff & (~old_pins); // make sure all other bits are 0 (after the 10 lowest order) |
saurabhmitra | 7:05d567c0f879 | 29 | switch(old_pins) { |
saurabhmitra | 7:05d567c0f879 | 30 | case 0x000: break; |
saurabhmitra | 7:05d567c0f879 | 31 | // Vowels on left hand - one per finger |
saurabhmitra | 7:05d567c0f879 | 32 | case 0x001: keyboard.printf("a");break; |
saurabhmitra | 7:05d567c0f879 | 33 | case 0x002: keyboard.printf("e");break; |
saurabhmitra | 7:05d567c0f879 | 34 | case 0x004: keyboard.printf("i");break; |
saurabhmitra | 7:05d567c0f879 | 35 | case 0x008: keyboard.printf("o");break; |
saurabhmitra | 7:05d567c0f879 | 36 | case 0x010: keyboard.printf("u");break; |
saurabhmitra | 7:05d567c0f879 | 37 | |
saurabhmitra | 7:05d567c0f879 | 38 | // Consonants on right hand, different combos |
saurabhmitra | 7:05d567c0f879 | 39 | case 0x020: keyboard.printf("t");break; |
saurabhmitra | 7:05d567c0f879 | 40 | case 0x040: keyboard.printf("n");break; |
saurabhmitra | 7:05d567c0f879 | 41 | case 0x080: keyboard.printf("s");break; |
saurabhmitra | 7:05d567c0f879 | 42 | case 0x100: keyboard.printf("h");break; |
saurabhmitra | 7:05d567c0f879 | 43 | case 0x200: keyboard.printf("r");break; |
saurabhmitra | 7:05d567c0f879 | 44 | case 0x060: keyboard.printf("d");break; |
saurabhmitra | 7:05d567c0f879 | 45 | case 0x0A0: keyboard.printf("l");break; |
saurabhmitra | 7:05d567c0f879 | 46 | case 0x120: keyboard.printf("c");break; |
saurabhmitra | 7:05d567c0f879 | 47 | case 0x220: keyboard.printf("m");break; |
saurabhmitra | 7:05d567c0f879 | 48 | case 0x0C0: keyboard.printf("w");break; |
saurabhmitra | 7:05d567c0f879 | 49 | case 0x140: keyboard.printf("f");break; |
saurabhmitra | 7:05d567c0f879 | 50 | case 0x240: keyboard.printf("g");break; |
saurabhmitra | 7:05d567c0f879 | 51 | case 0x180: keyboard.printf("y");break; |
saurabhmitra | 7:05d567c0f879 | 52 | case 0x280: keyboard.printf("p");break; |
saurabhmitra | 7:05d567c0f879 | 53 | case 0x300: keyboard.printf("b");break; |
saurabhmitra | 7:05d567c0f879 | 54 | case 0x0E0: keyboard.printf("v");break; |
saurabhmitra | 7:05d567c0f879 | 55 | case 0x160: keyboard.printf("k");break; |
saurabhmitra | 7:05d567c0f879 | 56 | case 0x260: keyboard.printf("j");break; |
saurabhmitra | 7:05d567c0f879 | 57 | case 0x1a0: keyboard.printf("x");break; |
saurabhmitra | 7:05d567c0f879 | 58 | case 0x2a0: keyboard.printf("q");break; |
saurabhmitra | 7:05d567c0f879 | 59 | case 0x320: keyboard.printf("z");break; |
saurabhmitra | 7:05d567c0f879 | 60 | |
saurabhmitra | 7:05d567c0f879 | 61 | // Special Keys |
saurabhmitra | 7:05d567c0f879 | 62 | case 0x003: keyboard.printf("\r\n");break; |
saurabhmitra | 7:05d567c0f879 | 63 | case 0x005: keyboard.printf(" ");break; |
saurabhmitra | 7:05d567c0f879 | 64 | case 0x009: keyboard.keyCode(KEY_CAPS_LOCK);break; |
saurabhmitra | 7:05d567c0f879 | 65 | case 0x011: keyboard.printf("\b");break; |
saurabhmitra | 7:05d567c0f879 | 66 | |
saurabhmitra | 7:05d567c0f879 | 67 | default: |
saurabhmitra | 7:05d567c0f879 | 68 | break; |
saurabhmitra | 7:05d567c0f879 | 69 | } |
saurabhmitra | 7:05d567c0f879 | 70 | } |
saurabhmitra | 7:05d567c0f879 | 71 | wait_ms(DELAY); |
samux | 1:291a88a2c151 | 72 | } |
samux | 4:f0df6aae7147 | 73 | } |