HelloKeypad3.ino (1589B)
1 #include <Keypad.h> 2 3 4 const byte ROWS = 2; // use 4X4 keypad for both instances 5 const byte COLS = 2; 6 char keys[ROWS][COLS] = { 7 {'1','2'}, 8 {'3','4'} 9 }; 10 byte rowPins[ROWS] = {5, 4}; //connect to the row pinouts of the keypad 11 byte colPins[COLS] = {7, 6}; //connect to the column pinouts of the keypad 12 Keypad kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 13 14 15 const byte ROWSR = 2; 16 const byte COLSR = 2; 17 char keysR[ROWSR][COLSR] = { 18 {'a','b'}, 19 {'c','d'} 20 }; 21 byte rowPinsR[ROWSR] = {3, 2}; //connect to the row pinouts of the keypad 22 byte colPinsR[COLSR] = {7, 6}; //connect to the column pinouts of the keypad 23 Keypad kpdR( makeKeymap(keysR), rowPinsR, colPinsR, ROWSR, COLSR ); 24 25 26 const byte ROWSUR = 4; 27 const byte COLSUR = 1; 28 char keysUR[ROWSUR][COLSUR] = { 29 {'M'}, 30 {'A'}, 31 {'R'}, 32 {'K'} 33 }; 34 // Digitran keypad, bit numbers of PCF8574 i/o port 35 byte rowPinsUR[ROWSUR] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad 36 byte colPinsUR[COLSUR] = {8}; //connect to the column pinouts of the keypad 37 38 Keypad kpdUR( makeKeymap(keysUR), rowPinsUR, colPinsUR, ROWSUR, COLSUR ); 39 40 41 void setup(){ 42 // Wire.begin( ); 43 kpdUR.begin( makeKeymap(keysUR) ); 44 kpdR.begin( makeKeymap(keysR) ); 45 kpd.begin( makeKeymap(keys) ); 46 Serial.begin(9600); 47 Serial.println( "start" ); 48 } 49 50 //byte alternate = false; 51 char key, keyR, keyUR; 52 void loop(){ 53 54 // alternate = !alternate; 55 key = kpd.getKey( ); 56 keyUR = kpdUR.getKey( ); 57 keyR = kpdR.getKey( ); 58 59 if (key){ 60 Serial.println(key); 61 } 62 if( keyR ) { 63 Serial.println( keyR ); 64 } 65 if( keyUR ) { 66 Serial.println( keyUR ); 67 } 68 }