VR FabLab - RoboVal
/
WorkingKeypad
Keypad library prototype
Diff: main.cpp
- Revision:
- 1:db0e3fb4d3c4
- Parent:
- 0:aed236b6c48e
--- a/main.cpp Mon May 21 21:59:31 2018 +0000 +++ b/main.cpp Wed Apr 10 22:08:13 2019 +0000 @@ -7,10 +7,10 @@ DigitalOut* _rows[4]; DigitalIn* _cols[4]; -TextLCD lcd(D2,D3,D4,D5,D6,D7); +TextLCD lcd(D2,D3,D4,D5,D6,D7); // Define your own keypad values -char Keytable[] = { +char Keytable[] = { '1', '2', '3', 'A', // r0 '4', '5', '6', 'B', // r1 '7', '8', '9', 'C', // r2 @@ -20,9 +20,9 @@ int getKeyIndex() { int result = -1; - for (int r = 0; r < 4; r++) { + for (int r = 0; r < 4 && result == -1; r++) { _rows[r]->write(1); - for(int c = 0;c < 4 ;c++){ + for(int c = 0; c < 4 && result == -1; c++){ DigitalIn *col = _cols[c]; if(col->read() == 1) { result = r*4+c; @@ -51,10 +51,10 @@ int main() { char key; lcd.locate(0,0); - lcd.printf("Clean"); - - init(); - + lcd.printf("Clean"); + + init(); + while(1) { key = getKey(); lcd.locate(0,1);