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
Diff: main.cpp
- Revision:
- 0:913f85486ace
- Child:
- 1:6b9c38f0638d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 22 15:59:43 2014 +0000 @@ -0,0 +1,201 @@ +#include "mbed.h" +#include "DebouncedEdgeIn.h" +#include "USBMouseKeyboard.h" + +DigitalOut myled1(LED_RED,1); +DigitalOut myled2(LED_GREEN,1); +DigitalOut myled3(LED_BLUE,1); + +DigitalIn b0(D13); +DigitalIn b1(D7); +DebouncedEdgeIn b2(D9); +DebouncedEdgeIn b3(D10); +DebouncedEdgeIn b4(D11); +DebouncedEdgeIn b5(D12); +DebouncedEdgeIn b6(D3); +DebouncedEdgeIn b7(D4); +DebouncedEdgeIn b8(D5); +DebouncedEdgeIn b9(D6); + +// SPST Pushbutton demo using internal PullUp function +// no external PullUp resistor needed +// Pushbutton from D2 to GND. +Serial pc(USBTX, USBRX); +//To output in terminal: +//ls /dev/tty.usbmodem* +//determine port number XXXX for input below +//screen /dev/tty.usbmodemXXXX 9600 + +//USBMouseKeyboard +//USBMouseKeyboard key_mouse; + +void a(){ + if(b0.read()&&b1.read()){ + pc.printf("a"); + //key_mouse.printf("a"); + } + if(!b0.read()&&b1.read()){ + pc.printf("h"); + //key_mouse.printf("h"); + } + if(b0.read()&&!b1.read()){ + pc.printf("o"); + //key_mouse.printf("o"); + } + if(!b0.read()&&!b1.read()){ + pc.printf("v"); + //key_mouse.printf("v"); + } +} + +void b(){ + if(b0.read()&&b1.read()){ + pc.printf("b"); + //key_mouse.printf("b"); + } + if(!b0.read()&&b1.read()){ + pc.printf("i"); + //key_mouse.printf("i"); + } + if(b0.read()&&!b1.read()){ + pc.printf("p"); + //key_mouse.printf("p"); + } + if(!b0.read()&&!b1.read()){ + pc.printf("w"); + //key_mouse.printf("w"); + } +} + +void c(){ + if(b0.read()&&b1.read()){ + pc.printf("c"); + //key_mouse.printf("cat"); + } + if(!b0.read()&&b1.read()){ + pc.printf("j"); + //key_mouse.printf("j"); + } + if(b0.read()&&!b1.read()){ + pc.printf("q"); + //key_mouse.printf("q"); + } + if(!b0.read()&&!b1.read()){ + pc.printf("x"); + //key_mouse.printf("x"); + } +} + +void d(){ + if(b0.read()&&b1.read()){ + pc.printf("d"); + //key_mouse.printf("d"); + } + if(!b0.read()&&b1.read()){ + pc.printf("k"); + //key_mouse.printf("k"); + } + if(b0.read()&&!b1.read()){ + pc.printf("r"); + //key_mouse.printf("r"); + } + if(!b0.read()&&!b1.read()){ + pc.printf("y"); + //key_mouse.printf("y"); + } +} + +void e(){ + if(b0.read()&&b1.read()){ + pc.printf("e"); + //key_mouse.printf("e"); + } + if(!b0.read()&&b1.read()){ + pc.printf("l"); + //key_mouse.printf("l"); + } + if(b0.read()&&!b1.read()){ + pc.printf("s"); + //key_mouse.printf("s"); + } + if(!b0.read()&&!b1.read()){ + pc.printf("z"); + //key_mouse.printf("z"); + } +} + +void f(){ + if(b0.read()&&b1.read()){ + pc.printf("f"); + //key_mouse.printf("f"); + } + if(!b0.read()&&b1.read()){ + pc.printf("m"); + //key_mouse.printf("m"); + } + if(b0.read()&&!b1.read()){ + pc.printf("t"); + //key_mouse.printf("t"); + } + if(!b0.read()&&!b1.read()){ + pc.printf("!"); + //key_mouse.printf("!"); + } +} + +void g(){ + if(b0.read()&&b1.read()){ + pc.printf("g"); + //key_mouse.printf("g"); + } + if(!b0.read()&&b1.read()){ + pc.printf("n"); + //key_mouse.printf("n"); + } + if(b0.read()&&!b1.read()){ + pc.printf("u"); + //key_mouse.printf("u"); + } + if(!b0.read()&&!b1.read()){ + pc.printf("?"); + //key_mouse.printf("?"); + } +} +void space(){ + pc.printf(" "); + //key_mouse.printf(" "); +} + +int main() { + b0.mode(PullUp); + b1.mode(PullUp); + b2.mode(PullUp); + b3.mode(PullUp); + b4.mode(PullUp); + b5.mode(PullUp); + b6.mode(PullUp); + b7.mode(PullUp); + b8.mode(PullUp); + b9.mode(PullUp); + + b2.fall(&a); + b3.fall(&b); + b4.fall(&c); + b5.fall(&d); + b6.fall(&e); + b7.fall(&f); + b8.fall(&g); + b9.fall(&space); + + pc.printf("Initialized\r\n"); + //key_mouse.printf("Initialized\r\n"); + + while(1) { + myled1 = b2; + myled2 = b3; + myled3 = b4; + //if(!b0){ +// key_mouse.printf("zz"); +// } + } +} \ No newline at end of file