Added extend button

This commit is contained in:
Will Bradley 2011-11-29 23:46:08 -07:00
parent 02435a78b1
commit 5f8d01fc27

View File

@ -112,6 +112,10 @@ void setup(){ // Runs once at Arduino boot-up
//Clear and initialize readers
wiegand26.initReaderOne(); //Set up Reader 1 and clear buffers.
// Initialize button input
pinMode(A5, INPUT);
digitalWrite(A5, HIGH);
//Initialize output relays
for(byte i=0; i<4; i++){
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
{
//////////////////////////
// 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
//////////////////////////
if(reader1Count >= 26)
{ // When tag presented to reader1 (No keypad on this reader)
lcd.clear();
lcd.print("connecting...");
delay(150);
lcd.clear();
Serial.println("connecting...");
@ -221,65 +294,12 @@ void loop() // Main branch, runs over and ov
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()
void lcdprint(int x, int y, char text) {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):