like this
void keypadEvent(KeypadEvent eKey) {
switch (eKey) {
case '*':
val = HIGH;
break;
I use this code but it does not work
#include <Keypad.h>
char keys[rows][cols] = { //@SIM char[][] keys = new char[][]{
{'1','2','3'}, //@SIM new char[]{'1','2','3'} ,
{'4','5','6'}, //@SIM new char[]{'4','5','6'} ,
{'7','8','9'}, //@SIM new char[]{'7','8','9'} ,
{'#','0','*'} //@SIM new char[]{'#','0','*'} ,
}; //@SIM };
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these pins,
// eg. ROW0 = Arduino pin2.
byte rowPins[] = { 0, 1, 2, 3 };
// Connect keypad COL0, COL1 and COL2 to these pins,
// eg. COL0 = Arduino pin6.
byte colPins[] = { 6, 5, 4 };
//create a new Keypad
Keypad keypad = Keypad(rowPins, colPins, sizeOf(rowPins) , sizeOf(colPins) );
#define ledPin 13
int val;
void setup()
{
digitalWrite(ledPin, HIGH); // sets the LED on
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener
}
void loop()
{
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey) {
switch (eKey) {
case '*':
val = HIGH;
break;
case '#':
digitalWrite(ledPin, LOW);
break;
case KEY_RELEASED:
Serial.println("Key Released");
break;
default:
if (eKey != NO_KEY){
Serial.println(eKey);
}
if (val == HIGH){
digitalWrite(ledPin, HIGH);
}
}
}