I'm new to Arduino and this is my first project I'm (kind of) doing on my own but I can't figure out what I'm doing wrong with the code. What I am trying to do is a motion detector alarm which I can turn off during 60 seconds with a passcode but I'm getting the error message "keypadEvent was not declared in this scope", what am I doing wrong? If there is anything else wrong with my code please tell me.
#include <Password.h>
#include <Keypad.h>
float sinVal;
int toneVal;
int brightness;
boolean alarmState;
Password password = Password( "4155" );
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] ={
{
'1', '2', '3', 'A', }
,
{
'4', '5', '6', 'B', }
,
{
'7', '8', '9', 'C', }
,
{
'*', '0', '#', 'D', }
};
byte rowPins[ROWS] = {
4, 3, 2, 1};
byte colPins[COLS] = {
13, 12, 11, 10 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (0, INPUT);
boolean alarmState = 0;
keypad.setDebounceTime(50);
keypad.addEventListener(keypadEvent);
}
void loop() {
noTone( 8 );
if(alarmState == 1){
if (digitalRead(0) == HIGH)(
alarm();
}
}
else{
keypad.getKey();
}
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
switch (eKey){
case '#':
checkPassword();
break;
break;
default:
password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
if (alarmState == 0){
alarmState = 1;
else{
alarmState = 0
}
}
}
else {
loop();
}
}
void alarm(){
for(int y=0; y<2; y++){
for(int x=0; x<180; x++){
sinVal =(sin(x*(3.1412/180)));
toneVal = 1500+(int(sinVal*1000));
brightness = int(sinVal*5);
tone(8, toneVal);
analogWrite(9, brightness);
delay(2);
}
}
}