
working, need to fix input bouncing
Dependencies: mbed
Revision 0:b44cdf7cb6a5, committed 2015-02-13
- Comitter:
- jaredwil
- Date:
- Fri Feb 13 19:22:58 2015 +0000
- Child:
- 1:ab859ed60719
- Commit message:
- This is working but there is a little bit of bouncing on inputs, but it will work
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 13 19:22:58 2015 +0000 @@ -0,0 +1,96 @@ +#include "mbed.h" +#include <map> + +//Initialize serial comms +Serial pc(USBTX, USBRX); + +PwmOut PWM1(p21); + +DigitalOut row1(p25); +DigitalOut row2(p22); +DigitalOut row3(p23); +DigitalOut row4(p24); + +DigitalIn col1(p20); +DigitalIn col2(p19); +DigitalIn col3(p18); +DigitalIn col4(p17); +Timer t1; + +//map +map<int, char> keypadMap; + +//Mores Code -> Character Map +void init(){ + keypadMap[0x11]='1'; + keypadMap[0x12]='2'; + keypadMap[0x14]='3'; + keypadMap[0x18]='A'; + keypadMap[0x21]='4'; + keypadMap[0x22]='5'; + keypadMap[0x24]='6'; + keypadMap[0x28]='B'; + keypadMap[0x41]='7'; + keypadMap[0x42]='8'; + keypadMap[0x44]='9'; + keypadMap[0x48]='C'; + keypadMap[0x81]='*'; + keypadMap[0x82]='0'; + keypadMap[0x84]='#'; + keypadMap[0x88]='D'; +} + +int main() { + init(); + //Initialize rows to 0 + row1 = 0; + row2 = 0; + row3 = 0; + row4 = 0; + t1.start(); + int input = 0x00; + while(1) { + //Keep each led lit for 4ms + switch(t1.read_ms()%4){ + case 0: + row1 = 1; + input |= 0x10; + row4 = 0; + break; + case 1: + row2 = 1; + input |= 0x20; + row1 = 0; + break; + case 2: + row3 = 1; + input |= 0x40; + row2 = 0; + break; + case 3: + row4 = 1; + input |= 0x80; + row3 = 0; + break; + } + if(col1 == 1) + input |= 0x01; + else if(col2 == 1) + input |= 0x02; + else if(col3 == 1) + input |= 0x04; + else if(col4 == 1) + input |= 0x08; + + char c = keypadMap[input]; //assign charcter based on input + + if(c != 0){ + pc.printf("%c\r",c); //print input and char + } + + + input = 0x00; + + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Feb 13 19:22:58 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa \ No newline at end of file