-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccess.cpp
More file actions
96 lines (84 loc) · 1.73 KB
/
Access.cpp
File metadata and controls
96 lines (84 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Implementation Access class
#include "Access.h"
// constructor 1
Access::Access()
{
pinCode = "0000";
doorLocked = 0;
pinAttemptNum = 0;
if(doorLocked == 1)
{
digitalWrite(45, HIGH); //Switch Solenoid ON
}
else if(doorLocked == 0)
{
digitalWrite(45, LOW); //Switch Solenoid OFF
} //Door is unlocked
}
// constructor 2
Access::Access(String pin)
{
pinCode = pin;
doorLocked = 0;
pinAttemptNum = 0;
if(doorLocked == 1){
digitalWrite(45, HIGH); //Switch Solenoid ON
}
else if(doorLocked == 0){
digitalWrite(45, LOW); //Switch Solenoid OFF
} //Door is unlocked
}
// public functions
void Access::changePin(String newPin)
{
pinCode = newPin;
Serial.print("Pin has been successfully changed to: ");
Serial.println(newPin);
}
void Access::Door(bool locked)
{
if(locked == 0)
{
digitalWrite(45, LOW);
doorLocked = 0;
Serial.print("Door is unlocked");
}
else if(locked == 1)
{
digitalWrite(45, HIGH);
doorLocked = 1;
Serial.print("* Door is locked");
}
}
void Access::attemptNum(int attempt)
{
if(attempt <= 2)
{
Serial.print(3 - attempt);
Serial.println(" Attempts remaining");
}
else if(attempt > 2)
{
// Maintenance etc...
}
}
bool Access::checkPin(String pin)
{
if(pin == pinCode)
{
Serial.println("Pin is correct");
pinAttemptNum = 0; // Restart number of attempts
return 1;
}
if(pin != defaultPin)
{
Serial.println("Pin is incorrect");
return 0;
}
if(doorLocked != 0)
{
pinAttemptNum++;
attemptNum(pinAttemptNum);
return 0;
}
}