Interactive Device Design
/
idd_hw2_alexandertyler_footTyping
Hands free keyboard reading.
Revision 0:b967cdcb226f, committed 2014-09-22
- Comitter:
- alexandertyler
- Date:
- Mon Sep 22 00:18:38 2014 +0000
- Commit message:
- Final project submission
Changed in this revision
diff -r 000000000000 -r b967cdcb226f USBDevice.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Mon Sep 22 00:18:38 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/USBDevice/#5bf05f9b3c7b
diff -r 000000000000 -r b967cdcb226f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 22 00:18:38 2014 +0000 @@ -0,0 +1,108 @@ +#include "mbed.h" +#include "USBKeyboard.h" +//#include "DebouncedEdgeIn.h" + +//DigitalOut ledG(LED_GREEN); +//DigitalOut ledR(LED_RED); +//DigitalOut ledB(LED_BLUE); +USBKeyboard keyboard; + +//Serial pc(USBTX, USBRX); + +DigitalIn diL(D2); +DigitalIn diR(D3); +//DebouncedEdgeIn diL(D2); +//DebouncedEdgeIn diR(D3); + +int lVal, rVal, preL = 1, preR = 1; +int bufferIndex = 0; +int ledIndex = 0; +int alphaIndex = 0; +bool keyUpdate = false; +DigitalOut ledArray[3] = {LED_RED, LED_GREEN, LED_BLUE}; +uint8_t alphaArray[31] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','.',8,10,'c'}; + + +/* +void bufferAdd(char* indexVal) { + buffer[bufferIndex] = indexVal; + bufferIndex++; + if (bufferIndex == 19) { + keyUpdate = true; + bufferIndex = 0; + } +} +*/ + +void poll() { + lVal = diL.read(); + rVal = diR.read(); +} + +void onRiseL(void) { + keyUpdate = true; + //update led value + ledArray[ledIndex] = 0; + + //do alphabet update + if (alphaIndex == 0) { + alphaIndex = 30; + } else { + alphaIndex -= 1; + } + + //do led update + if (ledIndex == 0) { + ledIndex = 2; + } else { + ledIndex -= 1; + } + + ledArray[ledIndex] = 1; + //pc.puts(alphaArray[alphaIndex]); +} + +void onRiseR(void) { + keyUpdate = true; + //change led value + ledArray[ledIndex] = 0; + + //do alphabet update + if (alphaIndex == 30) { + alphaIndex = 0; + } else { + alphaIndex += 1; + } + + //do led update + if (ledIndex == 2) { + ledIndex = 0; + } else { + ledIndex += 1; + } + + ledArray[ledIndex] = 1; + //pc.puts(alphaArray[alphaIndex]); +} + +int main() +{ + diL.mode(PullUp); + diR.mode(PullUp); + + while (true) { + poll(); + if (lVal == 0) {onRiseL();} + if (rVal == 0) {onRiseR();} + //keyboard.printf("hello from mbed.\n"); + if (keyUpdate) { + if (alphaIndex == 30) { + keyboard.keyCode('c', KEY_CTRL); + } else { + keyboard.keyCode(alphaArray[alphaIndex]); + } + keyUpdate = false; + wait(0.15); + } + } +}
diff -r 000000000000 -r b967cdcb226f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 22 00:18:38 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file