Created
April 13, 2018 17:46
-
-
Save mportatoes/a91c7d66f8430c85c20343136b3eeb20 to your computer and use it in GitHub Desktop.
Escape Room Prop Lockbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Keypad.h> | |
#include <Servo.h> // Include the Servo library | |
int servoPin = 3; // Declare the Servo pin | |
Servo Servo1; // Create a servo object | |
const byte n_rows = 4; | |
const byte n_cols = 4; | |
char keys[n_rows][n_cols] = { | |
{'1','2','3','A'}, | |
{'4','5','6','B'}, | |
{'7','8','9','C'}, | |
{'*','0','#','D'} | |
}; | |
int led = D8; | |
//String answer = "987654321"; | |
String answer = "7854487087"; | |
byte colPins[n_rows] = {D3, D2, D1, D0}; | |
byte rowPins[n_cols] = {D7, D6, D5, D4}; | |
char KeyArray[11]; | |
String KeyArrayString; | |
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols); | |
void setup(){ | |
Serial.begin(115200); | |
pinMode(led,OUTPUT); | |
digitalWrite(led,HIGH); | |
Servo1.attach(servoPin); // We need to attach the servo to the used pin number | |
Servo1.write(120); // Make servo go to 0 degrees | |
} | |
int i=0; | |
void loop(){ | |
char myKey = myKeypad.getKey(); | |
if (KeyArrayString==answer){ | |
Servo1.write(0); | |
digitalWrite(led,LOW); | |
exit; | |
} | |
else if (myKey != NULL && KeyArray[11] == NULL && String(myKey) != "C"){ | |
KeyArray[i]=myKey; | |
KeyArrayString=String(KeyArray); | |
Serial.print("Key: "); | |
Serial.println(KeyArrayString); | |
i++; | |
} | |
else if (KeyArray[11] != NULL || String(myKey) == "C" ){ | |
i=0; | |
digitalWrite(led,LOW); | |
delay(500); | |
digitalWrite(led,HIGH); | |
delay(500); | |
digitalWrite(led,LOW); | |
delay(500); | |
digitalWrite(led,HIGH); | |
delay(500); | |
digitalWrite(led,LOW); | |
delay(500); | |
digitalWrite(led,HIGH); | |
for (int x=0; x<=11; x++){ | |
KeyArray[x]=NULL; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment