mirror of
https://github.com/zyphlar/open-access-control-minimal-http.git
synced 2024-03-08 15:57:47 +00:00
Added extend button
This commit is contained in:
parent
02435a78b1
commit
5f8d01fc27
|
@ -112,6 +112,10 @@ void setup(){ // Runs once at Arduino boot-up
|
||||||
//Clear and initialize readers
|
//Clear and initialize readers
|
||||||
wiegand26.initReaderOne(); //Set up Reader 1 and clear buffers.
|
wiegand26.initReaderOne(); //Set up Reader 1 and clear buffers.
|
||||||
|
|
||||||
|
// Initialize button input
|
||||||
|
pinMode(A5, INPUT);
|
||||||
|
digitalWrite(A5, HIGH);
|
||||||
|
|
||||||
//Initialize output relays
|
//Initialize output relays
|
||||||
for(byte i=0; i<4; i++){
|
for(byte i=0; i<4; i++){
|
||||||
pinMode(relayPins[i], OUTPUT);
|
pinMode(relayPins[i], OUTPUT);
|
||||||
|
@ -132,12 +136,81 @@ void setup(){ // Runs once at Arduino boot-up
|
||||||
void loop() // Main branch, runs over and over again
|
void loop() // Main branch, runs over and over again
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//////////////////////////
|
||||||
|
// Normal operation section
|
||||||
|
//////////////////////////
|
||||||
|
|
||||||
|
// check timer -- if expired, remove authorization
|
||||||
|
|
||||||
|
if(authorized && relay1high) {
|
||||||
|
|
||||||
|
// Detect button push
|
||||||
|
lcd.setCursor(12,0);
|
||||||
|
lcd.print(analogRead(A5));
|
||||||
|
lcd.print(" ");
|
||||||
|
if (analogRead(A5) < 50) {
|
||||||
|
relay1timer = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate current time elapsed
|
||||||
|
long currentTime = millis() - relay1timer;
|
||||||
|
// if time entirely elapsed, deauthorize.
|
||||||
|
if(currentTime >= RELAYDELAY) {
|
||||||
|
authorized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate for display
|
||||||
|
long remaining = (RELAYDELAY - currentTime) / 1000;
|
||||||
|
long secRemaining = (RELAYDELAY - currentTime) / 1000 % 60;
|
||||||
|
long minRemaining = (RELAYDELAY - currentTime) / 1000 / 60 % 60;
|
||||||
|
long hrsRemaining = (RELAYDELAY - currentTime) / 1000 / 60 / 60;
|
||||||
|
|
||||||
|
// display timer & username
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
lcd.print(username);
|
||||||
|
lcd.setCursor(0, 1);
|
||||||
|
lcd.print(hrsRemaining);
|
||||||
|
lcd.print(":");
|
||||||
|
lcd.print(minRemaining);
|
||||||
|
lcd.print(":");
|
||||||
|
lcd.print(secRemaining);
|
||||||
|
lcd.print(" remain ");
|
||||||
|
}
|
||||||
|
if(!authorized && relay1high) {
|
||||||
|
lcd.clear();
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
lcd.print("Turning off.");
|
||||||
|
delay(500);
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// not authorized -- turn off relay
|
||||||
|
relayLow(1);
|
||||||
|
}
|
||||||
|
if(authorized && !relay1high) {
|
||||||
|
lcd.clear();
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
lcd.print("Turning on.");
|
||||||
|
delay(500);
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// authorized -- turn on relay
|
||||||
|
relayHigh(1);
|
||||||
|
}
|
||||||
|
if(!authorized && !relay1high) {
|
||||||
|
// display login message
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
lcd.print("Please login.");
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// Reader input/authentication section
|
// Reader input/authentication section
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
if(reader1Count >= 26)
|
if(reader1Count >= 26)
|
||||||
{ // When tag presented to reader1 (No keypad on this reader)
|
{ // When tag presented to reader1 (No keypad on this reader)
|
||||||
|
|
||||||
|
lcd.clear();
|
||||||
|
lcd.print("connecting...");
|
||||||
|
delay(150);
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
Serial.println("connecting...");
|
Serial.println("connecting...");
|
||||||
|
|
||||||
|
@ -221,65 +294,12 @@ void loop() // Main branch, runs over and ov
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////
|
|
||||||
// Normal operation section
|
|
||||||
//////////////////////////
|
|
||||||
|
|
||||||
// check timer -- if expired, remove authorization
|
|
||||||
|
|
||||||
if(authorized && relay1high) {
|
|
||||||
// calculate current time elapsed
|
|
||||||
long currentTime = millis() - relay1timer;
|
|
||||||
// if time entirely elapsed, deauthorize.
|
|
||||||
if(currentTime >= RELAYDELAY) {
|
|
||||||
authorized = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate for display
|
|
||||||
long remaining = (RELAYDELAY - currentTime) / 1000;
|
|
||||||
long secRemaining = (RELAYDELAY - currentTime) / 1000 % 60;
|
|
||||||
long minRemaining = (RELAYDELAY - currentTime) / 1000 / 60 % 60;
|
|
||||||
long hrsRemaining = (RELAYDELAY - currentTime) / 1000 / 60 / 60;
|
|
||||||
|
|
||||||
// display timer & username
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print(username);
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
lcd.print(hrsRemaining);
|
|
||||||
lcd.print(":");
|
|
||||||
lcd.print(minRemaining);
|
|
||||||
lcd.print(":");
|
|
||||||
lcd.print(secRemaining);
|
|
||||||
lcd.print(" remain");
|
|
||||||
}
|
|
||||||
if(!authorized && relay1high) {
|
|
||||||
lcd.clear();
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print("Turning off.");
|
|
||||||
delay(500);
|
|
||||||
lcd.clear();
|
|
||||||
|
|
||||||
// not authorized -- turn off relay
|
|
||||||
relayLow(1);
|
|
||||||
}
|
|
||||||
if(authorized && !relay1high) {
|
|
||||||
lcd.clear();
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print("Turning on.");
|
|
||||||
delay(500);
|
|
||||||
lcd.clear();
|
|
||||||
|
|
||||||
// authorized -- turn on relay
|
|
||||||
relayHigh(1);
|
|
||||||
}
|
|
||||||
if(!authorized && !relay1high) {
|
|
||||||
// display login message
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print("Please login.");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End of loop()
|
} // End of loop()
|
||||||
|
|
||||||
|
|
||||||
void lcdprint(int x, int y, char text) {
|
void lcdprint(int x, int y, char text) {
|
||||||
// set the cursor to column 0, line 1
|
// set the cursor to column 0, line 1
|
||||||
// (note: line 1 is the second row, since counting begins with 0):
|
// (note: line 1 is the second row, since counting begins with 0):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user