我想知道Arduino-Ide中Serial-Monitor中按下的按钮。我正在使用Arduino-Uno开发板,并且已通过I2C Connection与Arduino-Uno开发板连接了MCP23017 IC。我已经将5 * 5按钮矩阵与MCP23017的引脚相连。我正在使用joe young/arduino_keypads
库。无法查看在串行监视器中按下的按钮。
#include <Keypad_MC17.h>
#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#define I2CADDR 0
Adafruit_MCP23017 mcp_1;
const byte ROWS = 5; // five rows
const byte COLS = 5; // five columns
//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','4','5'},
{'6','7','8','9','A'},
{'B','C','D','E','F'},
{'G','H','I','J','K'},
{'L' ,'M','N','O','P'}
};
byte rowPins[ROWS] = { 15 , 14 , 13 , 12 , 11 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 10 , 9 ,8 , 7 , 6 }; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad_MC17 customKeypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS, I2CADDR);
void setup(){
Serial.begin(9600);
Serial.println("Program Started" );
//Begin I2C Devices
Wire.begin();
Wire.beginTransmission(0);
if (Wire.endTransmission(0) == 0) Serial.println("I2C Device Not Found 0x00");
else Serial.println("I2C 0x00 Connected Successfully");
mcp_1.begin();
// Begin Keypad Device
customKeypad.begin( );
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey != NO_KEY) {
Serial.println(customKey);
}
}