#include /* Ths sketch will monitor 5 pin conected to a MT8870DE DTMF decoder chip and send the key pressed to the computer by serial comunication. In addition, a certain combinaison of number will trigger a "unlock" or "boot" signal. The pwd in this case will be "8413". */ int Q1 = 2; /*Q1 bit*/ int Q2 = 3; /*Q2 bit*/ int Q3 = 4; /*Q3 bit*/ int Q4 = 5; /*Q4 bit*/ int StD = 6; /*Delayed Steering; will read high when tone is pressed*/ int keypressed ; char result ; /*the number presser stored as a character int pwdlvl = 0 ; /*Number of appended digits*/ Password password = Password( "8413" ); void setup() { Serial.begin(9600); /* Open serial com*/ /*Pins settings*/ pinMode(Q1, INPUT); pinMode(Q2, INPUT); pinMode(Q3, INPUT); pinMode(Q4, INPUT); pinMode(StD, INPUT); } void loop() { int toneHeard = digitalRead(StD); if (toneHeard == HIGH) { delay(250); keypressed = interpret() ; /* Go to the interpret function to get the keypressed*/ Serial.write(keypressed); password.append(keypressed); pwdlvl++; if (pwdlvl == 4){ Serial.println(); Serial.print("Guessing password... "); /*debuging purposes*/ delay(500); /*debuging purposes*/ if (password.evaluate()){ /*evaluate password*/ Serial.println("Valid Password"); Serial.print("Sending 5V signal for 3..."); delay(1000); Serial.print("2..."); delay(1000); Serial.print("1..."); delay(1000); Serial.println("0..."); password.reset(); /*Reset appended password*/ pwdlvl = 0; /*Reset the number of appended digits to 0*/ } else { Serial.println("Invalid Password"); password.reset(); /*Reset appended password*/ pwdlvl = 0; /*Reset the number of appended digits to 0*/ } } } delay(1); } int interpret() { int Q1State = digitalRead(Q1); int Q2State = digitalRead(Q2); int Q3State = digitalRead(Q3); int Q4State = digitalRead(Q4); if (Q1State == HIGH && Q2State == LOW && Q3State == LOW && Q4State == LOW){result = '1' ;} if (Q1State == LOW && Q2State == HIGH && Q3State == LOW && Q4State == LOW){result = '2' ;} if (Q1State == HIGH && Q2State == HIGH && Q3State == LOW && Q4State == LOW){result = '3' ;} if (Q1State == LOW && Q2State == LOW && Q3State == HIGH && Q4State == LOW){result = '4' ;} if (Q1State == HIGH && Q2State == LOW && Q3State == HIGH && Q4State == LOW){result = '5' ;} if (Q1State == LOW && Q2State == HIGH && Q3State == HIGH && Q4State == LOW){result = '6' ;} if (Q1State == HIGH && Q2State == HIGH && Q3State == HIGH && Q4State == LOW){result = '7' ;} if (Q1State == LOW && Q2State == LOW && Q3State == LOW && Q4State == HIGH){result = '8' ;} if (Q1State == HIGH && Q2State == LOW && Q3State == LOW && Q4State == HIGH){result = '9' ;} if (Q1State == LOW && Q2State == HIGH && Q3State == LOW && Q4State == HIGH){result = '0' ;} return result; }