dann11
Full Member level 3
Hi! I am trying to use the keypad.addEventListener() to call an event I did use it with keypadEvent,and then compiling my code gives me an Error 'keypadEvent' was not declared in this scope. Can you please help me where might have I gone wrong.
Code:
#include <Keypad.h>
//pin assignments
int latchPin = 15;
int clockPin = 14;
int dataPin = 16;
int keySwitch = 9;
int ledActual = 17;
int ledTarget = 18;
int ledTactTime = 19;
//global variables
byte digitBuffer[6] = {0};
int digitScan = 1;
byte valueKeypad = 0;
byte num = 0;
//keypad
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'#','0','*','D'},
};
byte rowPins[ROWS] = {0 , 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7};//nnect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//display 0,1,2,3,4,5,6,7,8,9:
byte datArray[10] = {B01111101, B00100001, B01010111, B01110011, B00101011, B01111010, B01111110, B01100001, B01111111, B01111011};
void setup()
{
//Serial.begin(9600);
//pin designation
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(keySwitch, INPUT);
pinMode(ledActual, OUTPUT);
pinMode(ledTarget, OUTPUT);
pinMode(ledTactTime, OUTPUT);
//initialize display
digitalWrite(latchPin, LOW);
shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
digitalWrite(latchPin, HIGH); //pull the latchPin to save the data
keypad.addEventListener(keypadEvent);
}
void keypadEvent(KeypadEvent key)
{
if (keySwitch == LOW)
{
switch(keypad.getState())
{
case PRESSED:
switch(key);
{
case 'A':
digitalWrite(ledActual, HIGH);
//transmit data to the display - Actual Value
break;
case '3':
digitalWrite(ledTarget, HIGH);
//transmit data to the display - Target Value
break;
case '2':
digitalWrite(ledTactTime, HIGH);
//transmit data to the display - Time Value
break;
case '1';
digitalWrite(ledActual, LOW);
digitalWrite(ledTarget, LOW);
digitalWrite(ledTactTime, LOW);
//save the Actual Value to the Actual Variable
break;
}
break;
case RELEASED:
switch(key);
{
case 'A':
digitalWrite(ledActual, HIGH);
keypadAction();
//transmit data to the display - Actual Value
break;
case '3':
digitalWrite(ledTarget, HIGH);
keypadAction();
//transmit data to the display - Target Value
break;
case '2':
digitalWrite(ledTactTime, HIGH);
keypadAction();
//transmit data to the display - Time Value
break;
case '1';
digitalWrite(ledActual, LOW);
digitalWrite(ledTarget, LOW);
digitalWrite(ledTactTime, LOW);
//save the Actual Value to the Actual Variable
break;
}
break;
case HOLD:
switch(key);
{
case 'A':
digitalWrite(ledActual, HIGH);
//transmit data to the display - Actual Value
break;
case '3':
digitalWrite(ledTarget, HIGH);
//transmit data to the display - Target Value
break;
case '2':
digitalWrite(ledTactTime, HIGH);
break;
case '1';
digitalWrite(ledActual, LOW);
digitalWrite(ledTarget, LOW);
digitalWrite(ledTactTime, LOW);
break;
}
break;
}
}
}