Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <Keypad.h>
- int signalPin = A0;
- #define Password_Length 8
- char Data[Password_Length];
- char Master[Password_Length] = "123A456";
- byte data_count = 0, master_count = 0;
- bool Pass_is_good;
- char customKey;
- const byte ROWS = 4;
- const byte COLS = 4;
- char hexaKeys[ROWS][COLS] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins[ROWS] = {9, 8, 7, 6};
- byte colPins[COLS] = {5, 4, 3, 2};
- Servo myServo;
- Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup() {
- pinMode(signalPin, OUTPUT);
- digitalWrite(signalPin, LOW);
- myServo.attach(2);
- myServo.write(0);
- delay(5000);
- }
- void loop() {
- customKey = customKeypad.getKey();
- if (customKey) {
- Data[data_count] = customKey;
- Serial.print(Data[data_count]);
- data_count++;
- }
- if (data_count == Password_Length - 1) {
- lcd.clear();
- if (!strcmp(Data, Master)) {
- Serial.println();
- // Open Door: Servo + Solienoid
- openDoorAction();
- }
- else {
- Serial.println();
- // Close Door: Servo + Solienoid
- closeDoorAction();
- }
- }
- }// end of LOOP
- void clearData1() {
- while (data_count != 0) {
- Data[data_count--] = 0;
- }
- return;
- }
- void openDoorAction() {
- digitalWrite(signalPin, HIGH);
- myServo.write(90);
- delay(5000);
- digitalWrite(signalPin, LOW);
- myServo.write(0);
- clearData1();
- }
- void closeDoorAction() {
- myServo.write(0);
- delay(1000);
- clearData1();
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment