Classic multi-tap touch device with enter key. Allows for multiple keys to be entered at once.
Dependencies: DebouncedEdgeIn USBDevice mbed
Fork of idd_hw2_martincowell_bicyclehid by
main.cpp@0:913f85486ace, 2014-09-22 (annotated)
- Committer:
- martincowell
- Date:
- Mon Sep 22 15:59:43 2014 +0000
- Revision:
- 0:913f85486ace
- Child:
- 1:6b9c38f0638d
Text entry while you ride a bike! Because you don't already have enough to think about while riding.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martincowell | 0:913f85486ace | 1 | #include "mbed.h" |
martincowell | 0:913f85486ace | 2 | #include "DebouncedEdgeIn.h" |
martincowell | 0:913f85486ace | 3 | #include "USBMouseKeyboard.h" |
martincowell | 0:913f85486ace | 4 | |
martincowell | 0:913f85486ace | 5 | DigitalOut myled1(LED_RED,1); |
martincowell | 0:913f85486ace | 6 | DigitalOut myled2(LED_GREEN,1); |
martincowell | 0:913f85486ace | 7 | DigitalOut myled3(LED_BLUE,1); |
martincowell | 0:913f85486ace | 8 | |
martincowell | 0:913f85486ace | 9 | DigitalIn b0(D13); |
martincowell | 0:913f85486ace | 10 | DigitalIn b1(D7); |
martincowell | 0:913f85486ace | 11 | DebouncedEdgeIn b2(D9); |
martincowell | 0:913f85486ace | 12 | DebouncedEdgeIn b3(D10); |
martincowell | 0:913f85486ace | 13 | DebouncedEdgeIn b4(D11); |
martincowell | 0:913f85486ace | 14 | DebouncedEdgeIn b5(D12); |
martincowell | 0:913f85486ace | 15 | DebouncedEdgeIn b6(D3); |
martincowell | 0:913f85486ace | 16 | DebouncedEdgeIn b7(D4); |
martincowell | 0:913f85486ace | 17 | DebouncedEdgeIn b8(D5); |
martincowell | 0:913f85486ace | 18 | DebouncedEdgeIn b9(D6); |
martincowell | 0:913f85486ace | 19 | |
martincowell | 0:913f85486ace | 20 | // SPST Pushbutton demo using internal PullUp function |
martincowell | 0:913f85486ace | 21 | // no external PullUp resistor needed |
martincowell | 0:913f85486ace | 22 | // Pushbutton from D2 to GND. |
martincowell | 0:913f85486ace | 23 | Serial pc(USBTX, USBRX); |
martincowell | 0:913f85486ace | 24 | //To output in terminal: |
martincowell | 0:913f85486ace | 25 | //ls /dev/tty.usbmodem* |
martincowell | 0:913f85486ace | 26 | //determine port number XXXX for input below |
martincowell | 0:913f85486ace | 27 | //screen /dev/tty.usbmodemXXXX 9600 |
martincowell | 0:913f85486ace | 28 | |
martincowell | 0:913f85486ace | 29 | //USBMouseKeyboard |
martincowell | 0:913f85486ace | 30 | //USBMouseKeyboard key_mouse; |
martincowell | 0:913f85486ace | 31 | |
martincowell | 0:913f85486ace | 32 | void a(){ |
martincowell | 0:913f85486ace | 33 | if(b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 34 | pc.printf("a"); |
martincowell | 0:913f85486ace | 35 | //key_mouse.printf("a"); |
martincowell | 0:913f85486ace | 36 | } |
martincowell | 0:913f85486ace | 37 | if(!b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 38 | pc.printf("h"); |
martincowell | 0:913f85486ace | 39 | //key_mouse.printf("h"); |
martincowell | 0:913f85486ace | 40 | } |
martincowell | 0:913f85486ace | 41 | if(b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 42 | pc.printf("o"); |
martincowell | 0:913f85486ace | 43 | //key_mouse.printf("o"); |
martincowell | 0:913f85486ace | 44 | } |
martincowell | 0:913f85486ace | 45 | if(!b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 46 | pc.printf("v"); |
martincowell | 0:913f85486ace | 47 | //key_mouse.printf("v"); |
martincowell | 0:913f85486ace | 48 | } |
martincowell | 0:913f85486ace | 49 | } |
martincowell | 0:913f85486ace | 50 | |
martincowell | 0:913f85486ace | 51 | void b(){ |
martincowell | 0:913f85486ace | 52 | if(b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 53 | pc.printf("b"); |
martincowell | 0:913f85486ace | 54 | //key_mouse.printf("b"); |
martincowell | 0:913f85486ace | 55 | } |
martincowell | 0:913f85486ace | 56 | if(!b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 57 | pc.printf("i"); |
martincowell | 0:913f85486ace | 58 | //key_mouse.printf("i"); |
martincowell | 0:913f85486ace | 59 | } |
martincowell | 0:913f85486ace | 60 | if(b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 61 | pc.printf("p"); |
martincowell | 0:913f85486ace | 62 | //key_mouse.printf("p"); |
martincowell | 0:913f85486ace | 63 | } |
martincowell | 0:913f85486ace | 64 | if(!b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 65 | pc.printf("w"); |
martincowell | 0:913f85486ace | 66 | //key_mouse.printf("w"); |
martincowell | 0:913f85486ace | 67 | } |
martincowell | 0:913f85486ace | 68 | } |
martincowell | 0:913f85486ace | 69 | |
martincowell | 0:913f85486ace | 70 | void c(){ |
martincowell | 0:913f85486ace | 71 | if(b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 72 | pc.printf("c"); |
martincowell | 0:913f85486ace | 73 | //key_mouse.printf("cat"); |
martincowell | 0:913f85486ace | 74 | } |
martincowell | 0:913f85486ace | 75 | if(!b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 76 | pc.printf("j"); |
martincowell | 0:913f85486ace | 77 | //key_mouse.printf("j"); |
martincowell | 0:913f85486ace | 78 | } |
martincowell | 0:913f85486ace | 79 | if(b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 80 | pc.printf("q"); |
martincowell | 0:913f85486ace | 81 | //key_mouse.printf("q"); |
martincowell | 0:913f85486ace | 82 | } |
martincowell | 0:913f85486ace | 83 | if(!b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 84 | pc.printf("x"); |
martincowell | 0:913f85486ace | 85 | //key_mouse.printf("x"); |
martincowell | 0:913f85486ace | 86 | } |
martincowell | 0:913f85486ace | 87 | } |
martincowell | 0:913f85486ace | 88 | |
martincowell | 0:913f85486ace | 89 | void d(){ |
martincowell | 0:913f85486ace | 90 | if(b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 91 | pc.printf("d"); |
martincowell | 0:913f85486ace | 92 | //key_mouse.printf("d"); |
martincowell | 0:913f85486ace | 93 | } |
martincowell | 0:913f85486ace | 94 | if(!b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 95 | pc.printf("k"); |
martincowell | 0:913f85486ace | 96 | //key_mouse.printf("k"); |
martincowell | 0:913f85486ace | 97 | } |
martincowell | 0:913f85486ace | 98 | if(b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 99 | pc.printf("r"); |
martincowell | 0:913f85486ace | 100 | //key_mouse.printf("r"); |
martincowell | 0:913f85486ace | 101 | } |
martincowell | 0:913f85486ace | 102 | if(!b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 103 | pc.printf("y"); |
martincowell | 0:913f85486ace | 104 | //key_mouse.printf("y"); |
martincowell | 0:913f85486ace | 105 | } |
martincowell | 0:913f85486ace | 106 | } |
martincowell | 0:913f85486ace | 107 | |
martincowell | 0:913f85486ace | 108 | void e(){ |
martincowell | 0:913f85486ace | 109 | if(b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 110 | pc.printf("e"); |
martincowell | 0:913f85486ace | 111 | //key_mouse.printf("e"); |
martincowell | 0:913f85486ace | 112 | } |
martincowell | 0:913f85486ace | 113 | if(!b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 114 | pc.printf("l"); |
martincowell | 0:913f85486ace | 115 | //key_mouse.printf("l"); |
martincowell | 0:913f85486ace | 116 | } |
martincowell | 0:913f85486ace | 117 | if(b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 118 | pc.printf("s"); |
martincowell | 0:913f85486ace | 119 | //key_mouse.printf("s"); |
martincowell | 0:913f85486ace | 120 | } |
martincowell | 0:913f85486ace | 121 | if(!b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 122 | pc.printf("z"); |
martincowell | 0:913f85486ace | 123 | //key_mouse.printf("z"); |
martincowell | 0:913f85486ace | 124 | } |
martincowell | 0:913f85486ace | 125 | } |
martincowell | 0:913f85486ace | 126 | |
martincowell | 0:913f85486ace | 127 | void f(){ |
martincowell | 0:913f85486ace | 128 | if(b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 129 | pc.printf("f"); |
martincowell | 0:913f85486ace | 130 | //key_mouse.printf("f"); |
martincowell | 0:913f85486ace | 131 | } |
martincowell | 0:913f85486ace | 132 | if(!b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 133 | pc.printf("m"); |
martincowell | 0:913f85486ace | 134 | //key_mouse.printf("m"); |
martincowell | 0:913f85486ace | 135 | } |
martincowell | 0:913f85486ace | 136 | if(b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 137 | pc.printf("t"); |
martincowell | 0:913f85486ace | 138 | //key_mouse.printf("t"); |
martincowell | 0:913f85486ace | 139 | } |
martincowell | 0:913f85486ace | 140 | if(!b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 141 | pc.printf("!"); |
martincowell | 0:913f85486ace | 142 | //key_mouse.printf("!"); |
martincowell | 0:913f85486ace | 143 | } |
martincowell | 0:913f85486ace | 144 | } |
martincowell | 0:913f85486ace | 145 | |
martincowell | 0:913f85486ace | 146 | void g(){ |
martincowell | 0:913f85486ace | 147 | if(b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 148 | pc.printf("g"); |
martincowell | 0:913f85486ace | 149 | //key_mouse.printf("g"); |
martincowell | 0:913f85486ace | 150 | } |
martincowell | 0:913f85486ace | 151 | if(!b0.read()&&b1.read()){ |
martincowell | 0:913f85486ace | 152 | pc.printf("n"); |
martincowell | 0:913f85486ace | 153 | //key_mouse.printf("n"); |
martincowell | 0:913f85486ace | 154 | } |
martincowell | 0:913f85486ace | 155 | if(b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 156 | pc.printf("u"); |
martincowell | 0:913f85486ace | 157 | //key_mouse.printf("u"); |
martincowell | 0:913f85486ace | 158 | } |
martincowell | 0:913f85486ace | 159 | if(!b0.read()&&!b1.read()){ |
martincowell | 0:913f85486ace | 160 | pc.printf("?"); |
martincowell | 0:913f85486ace | 161 | //key_mouse.printf("?"); |
martincowell | 0:913f85486ace | 162 | } |
martincowell | 0:913f85486ace | 163 | } |
martincowell | 0:913f85486ace | 164 | void space(){ |
martincowell | 0:913f85486ace | 165 | pc.printf(" "); |
martincowell | 0:913f85486ace | 166 | //key_mouse.printf(" "); |
martincowell | 0:913f85486ace | 167 | } |
martincowell | 0:913f85486ace | 168 | |
martincowell | 0:913f85486ace | 169 | int main() { |
martincowell | 0:913f85486ace | 170 | b0.mode(PullUp); |
martincowell | 0:913f85486ace | 171 | b1.mode(PullUp); |
martincowell | 0:913f85486ace | 172 | b2.mode(PullUp); |
martincowell | 0:913f85486ace | 173 | b3.mode(PullUp); |
martincowell | 0:913f85486ace | 174 | b4.mode(PullUp); |
martincowell | 0:913f85486ace | 175 | b5.mode(PullUp); |
martincowell | 0:913f85486ace | 176 | b6.mode(PullUp); |
martincowell | 0:913f85486ace | 177 | b7.mode(PullUp); |
martincowell | 0:913f85486ace | 178 | b8.mode(PullUp); |
martincowell | 0:913f85486ace | 179 | b9.mode(PullUp); |
martincowell | 0:913f85486ace | 180 | |
martincowell | 0:913f85486ace | 181 | b2.fall(&a); |
martincowell | 0:913f85486ace | 182 | b3.fall(&b); |
martincowell | 0:913f85486ace | 183 | b4.fall(&c); |
martincowell | 0:913f85486ace | 184 | b5.fall(&d); |
martincowell | 0:913f85486ace | 185 | b6.fall(&e); |
martincowell | 0:913f85486ace | 186 | b7.fall(&f); |
martincowell | 0:913f85486ace | 187 | b8.fall(&g); |
martincowell | 0:913f85486ace | 188 | b9.fall(&space); |
martincowell | 0:913f85486ace | 189 | |
martincowell | 0:913f85486ace | 190 | pc.printf("Initialized\r\n"); |
martincowell | 0:913f85486ace | 191 | //key_mouse.printf("Initialized\r\n"); |
martincowell | 0:913f85486ace | 192 | |
martincowell | 0:913f85486ace | 193 | while(1) { |
martincowell | 0:913f85486ace | 194 | myled1 = b2; |
martincowell | 0:913f85486ace | 195 | myled2 = b3; |
martincowell | 0:913f85486ace | 196 | myled3 = b4; |
martincowell | 0:913f85486ace | 197 | //if(!b0){ |
martincowell | 0:913f85486ace | 198 | // key_mouse.printf("zz"); |
martincowell | 0:913f85486ace | 199 | // } |
martincowell | 0:913f85486ace | 200 | } |
martincowell | 0:913f85486ace | 201 | } |