#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
byte rowPins[ROWS] = {13,12,11,10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9,8,7,6}; //connect to the column pinouts of the keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
String msg;
void setup() {
Serial.begin(9600);
loopCount = 0;
startTime = millis();
msg = "";
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
}
void loop() {
loopCount++;
if ( (millis()-startTime)>5000 ) {
startTime = millis();
loopCount = 0;
}
// Fills kpd.key[ ] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (keypad.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( keypad.key*.stateChanged ) // Only find keys that have changed state.*
- {*
_ switch (keypad.key*.kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED*_
* case PRESSED:*
* msg = " PRESSED.";*
* break;*
* case HOLD:*
* msg = " HOLD.";*
_ if(keypad.key*.kchar=='A'){
digitalWrite(2,HIGH);}
if(keypad.key.kchar=='B'){
digitalWrite(3,HIGH);}
break;
case RELEASED:
msg = " RELEASED.";
digitalWrite(2,LOW);
digitalWrite(3,LOW);*_
* break;*
* case IDLE:*
* msg = " IDLE.";*
* }*
* Serial.print("Key ");*
_ Serial.print(keypad.key*.kchar);
Serial.println(msg);
}
}
}
} // End loop*_