I followed this page but I could not get password.h to work so I did it a different way. I however can not get my audio to play per pin. Anyone know how to write this in?
//phone test sketch eagon 10/30/19
//when lift handset off dialtone runs, when press a button dial tone stops and button presses make sounds, when put in password it sends
//signal to the relay until reset button is pressed//achievement audio does not play after password is correct
#include <Key.h>
#include <Keypad.h>char* secretCode = "4567";
int position = 0;const byte rows = 4;
const byte cols = 4;
char keys[rows][cols] = {
{'1', '4', '7', '*'},
{'2', '5', '8', '0'},
{'3', '6', '9', '#'},
{'A', 'A', 'C', 'B'}
};byte rowPins[rows] = {9, 8, 7, 6};
byte colPins[cols] = {5, 4, 3, 2};Keypad keypad = Keypad(makeKeymap(keys),
rowPins, colPins,
rows, cols);const int dialtone = 12 ;
const int keytone = 13 ;
int relay = 11;
const int handset = 10;// variables will change:
int handsetState = 0; // variable for reading the pushbutton statusvoid setup()
{setLocked(true);
pinMode(dialtone, OUTPUT);
pinMode(keytone, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(handset, INPUT_PULLUP);}
void loop()
{// read the state of the pushbutton value:
handsetState = digitalRead(handset);// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (handsetState == LOW) {
// turn LED on:
digitalWrite(dialtone, HIGH);} else {
// turn LED off:
digitalWrite(dialtone, LOW);
}
char key = keypad.getKey();
if (key == 'A' || key == 'B') {
position = 0;
setLocked(true);
}if (key == secretCode[position]) {
position++;
}if (position == 4) {
setLocked(false);
}
delay(50);
}void setLocked(int locked)
{if (locked) {
digitalWrite(relay, LOW);}
else {
digitalWrite(relay, HIGH);}
}