Date created: Tuesday, March 3, 2015 10:04:05 PM. Last modified: Tuesday, March 3, 2015 10:04:05 PM
4x4 Keypad I2C 8bit IO Expander
PCF8574A - Manual
4x4 8 wire keypad membrane
This is a great example library for use with keypads and in I2C port expander.
Note: With A0, A1 and A2 grounded on this I2C chip the address becomes 0x38.
#include <Keypad_I2C.h> #include <Keypad.h> #include <Wire.h> // A0, A1, A2 all to GND #define I2CADDR 0x38 const byte ROWS = 4; //four rows const byte COLS = 4; //four columns char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; // Digitran keypad, bit numbers of PCF8574 i/o port byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad Keypad_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574 ); void setup(){ Wire.begin( ); kpd.begin( makeKeymap(keys) ); Serial.begin(9600); Serial.println( "start" ); } void loop(){ char key = kpd.getKey(); if (key){ Serial.println(key); } }
Previous page: 4x4 Keypad
Next page: Bhone - Part 1