#include <SPI.h>
#define NUMBER 4
int input_pin[NUMBER] = {3, 4, 5, 6};
byte current_state[NUMBER] = {0};
char nextChar;
int tmp;
//const byte set_pass[]={7,7,7}; // The DTMF Value for 4 Digits of Password
//byte recvd_pass[3]; // a variable to store the password received
int StD = 2; //i added
int val = 0; //i added
int keypressed;
//char result;
int count = 0; //was pwdlvl
int i = 0;
//char password = ("7");
//int interpret;
// pinMode(2,INPUT); // Steered delay Pin (INT 0)
// pinMode(3,INPUT); // q1
// pinMode(4,INPUT); // q2
// pinMode(5,INPUT); // q3
// pinMode(6,INPUT); // q4 //was pin 1
// attachInterrupt(0,dtmf,RISING);
//}
//byte value = 0;
void setup() {
pinMode(StD, INPUT); // i added
Serial.begin(9600);
//for (int i = 0; i < NUMBER; i++) pinMode(input_pin[i], INPUT);
}
/*
0000=needs to be ignored. The default state of the inputs will be 0000.
0001= 1 through 1000 = 8
*/
void loop() {
int value = 0;
//The first part of the loop is meant to recognize the state change of the inputs.
for (int a = 0; a < 4; a++) {
current_state[a] = digitalRead(input_pin[a]);
value = value * 2 + current_state[a];
//save the new data to the SD card
//for (byte a = 0; a < 4; a = a + 1) {
//Serial.println(current_state[a]);
//}
//tell the bench the state has been changed
// Serial.println(current_state[a]);
// delay(1000);
}
//Serial.print ("Global state : ");
//Serial.print(value);
//delay(1000);
int toneHeard = digitalRead(StD);
if (toneHeard == HIGH) {
delay(250);
keypressed = (value);
Serial.print(keypressed);
//password.append(keypressed);
count++; // worked
}
//pwdlvl++; // increment count
if(count==3){ // if count is 4, then we need to match the password received to the passwors stored
//if(recvd_pass[0]==set_pass[0] && recvd_pass[1]==set_pass[1] && recvd_pass[2]==set_pass[2]; //&& recvd_pass[3]==set_pass[3]) // check if passwords match
val=0;
// 'modified' will be your desired output
//}
//if (pwdlvl == 3){
//Serial.println();
Serial.print("pass3.. ");
//Serial.print(value);
delay(500);
//Serial.print (i); //I added // if matched set the login flag
//if (password.evaluate()){
// Serial.println("Valid Password");
//value = 0;
count = 0;
}
}