
working, need to fix input bouncing
Dependencies: mbed
Revision 2:54ae225e6203, committed 2015-02-22
- Comitter:
- jaredwil
- Date:
- Sun Feb 22 17:59:32 2015 +0000
- Parent:
- 1:ab859ed60719
- Child:
- 3:3e18de5a9cce
- Commit message:
- commented;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Feb 17 17:57:23 2015 +0000 +++ b/main.cpp Sun Feb 22 17:59:32 2015 +0000 @@ -4,12 +4,15 @@ //Initialize serial comms Serial pc(USBTX, USBRX); +//Initialize PMW PwmOut PWM1(p21); -DigitalOut row1(p25); -DigitalOut row2(p22); -DigitalOut row3(p23); -DigitalOut row4(p24); + +//Initialize Keypad I/O +DigitalOut row1(p26); +DigitalOut row2(p23); +DigitalOut row3(p24); +DigitalOut row4(p25); DigitalIn col1(p20); DigitalIn col2(p19); @@ -17,10 +20,13 @@ DigitalIn col4(p17); Timer t1; -//map +//map used for keypad map<int, char> keypadMap; -//Mores Code -> Character Map + +//Map for keypad +//First 4 bits corrospond to active column +//Last 4 bits corrospond to active row void init(){ keypadMap[0x11]='1'; keypadMap[0x12]='2'; @@ -73,25 +79,26 @@ row4 = 1; input |= 0x80; 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; - - + + } + //Pull the value from each column and check to see if 1 + 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 + //Print to the terminal the character if available + if(c != 0){ + pc.printf("%c\r",c); //print input and char + } + + //reset input + input = 0x00; } }