doorlock2.ino (1082B)
1 /* @file HelloKeypad.pde 2 || @version 1.0 3 || @author Alexander Brevig 4 || @contact alexanderbrevig@gmail.com 5 || 6 || @description 7 || | Demonstrates the simplest use of the matrix Keypad library. 8 || # 9 */ 10 #include <Keypad.h> 11 String codelock; 12 const byte ROWS = 4; //four rows 13 const byte COLS = 3; //three columns 14 char keys[ROWS][COLS] = { 15 {'1','2','3'}, 16 {'4','5','6'}, 17 {'7','8','9'}, 18 {'*','0','#'} 19 }; 20 byte rowPins[ROWS] = {1, 2, 3, 4}; //connect to the row pinouts of the keypad 21 byte colPins[COLS] = {5, 6, 7}; //connect to the column pinouts of the keypad 22 23 Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 24 25 void setup(){ 26 Serial.begin(9600); 27 pinMode(10, OUTPUT); 28 digitalWrite(10, HIGH); 29 } 30 31 void loop(){ 32 char key = keypad.getKey(); 33 if (key){ 34 codelock += key; 35 Serial.println(key); 36 Serial.println(codelock); 37 } 38 if (key == '*'){ 39 codelock = ""; 40 } 41 if (codelock == "0550#"){ 42 codelock = ""; 43 digitalWrite(10, LOW); 44 delay(5000); 45 digitalWrite(10, HIGH); 46 } 47 if (codelock.length() > 100) { 48 codelock = ""; 49 } 50 }