diff --git a/chicken_door.ino b/chicken_door.ino index dc6b9e9..439049f 100644 --- a/chicken_door.ino +++ b/chicken_door.ino @@ -15,12 +15,13 @@ #define DPRINTLN(str) #endif -#define ONOFF_PIN 5 -#define FWREV_PIN 3 -#define DOOR_CONTACT_PIN 4 -#define BUTTON_PIN 2 -#define PHOTOCELL_PIN 0 -#define TEMP_SUPPLY_PIN 6 +#define PHOTOCELL_PIN 0 +#define DOOR_CONTACT_2_PIN 2 +#define FWREV_PIN 3 +#define DOOR_CONTACT_1_PIN 4 +#define ONOFF_PIN 5 +#define TEMP_SUPPLY_PIN 6 +#define AUX_BUTTON_PIN 7 #define INITIALIZE 0 #define WAIT_FOR_LIGHT 1 @@ -31,7 +32,8 @@ #define BRIGHTNESS_SIZE 3 #define BRIGHT_THRESHOLD 600 #define OPEN_DELAY 6400 -#define MAX_CLOSE_TIME 8000 +#define MAX_CLOSE_TIME 4000 +#define MAX_OPEN_TIME 4000 #define HYSTERESIS 50 word brightness[BRIGHTNESS_SIZE]; @@ -41,9 +43,11 @@ void setup() { pinMode(ONOFF_PIN, OUTPUT); pinMode(FWREV_PIN, OUTPUT); - pinMode(DOOR_CONTACT_PIN, INPUT); - digitalWrite(DOOR_CONTACT_PIN, LOW); - pinMode(BUTTON_PIN, INPUT); + pinMode(DOOR_CONTACT_1_PIN, INPUT); + digitalWrite(DOOR_CONTACT_1_PIN, LOW); + pinMode(DOOR_CONTACT_2_PIN, INPUT); + digitalWrite(DOOR_CONTACT_2_PIN, LOW); + pinMode(AUX_BUTTON_PIN, INPUT); pinMode(TEMP_SUPPLY_PIN, OUTPUT); digitalWrite(TEMP_SUPPLY_PIN, HIGH); // for initial photocell reading // attachInterrupt(0, pressButton, LOW); @@ -78,7 +82,7 @@ delay(100); millisLeft -= 100; digitalWrite(ONOFF_PIN, HIGH); - while ((digitalRead(DOOR_CONTACT_PIN) == LOW) && (millisLeft > 0)) { + while ((digitalRead(DOOR_CONTACT_2_PIN) == LOW) && (millisLeft > 0)) { delay(100); millisLeft -= 100; } @@ -89,11 +93,17 @@ } void lowerDoor() { + long millisLeft = MAX_CLOSE_TIME; digitalWrite(TEMP_SUPPLY_PIN, HIGH); digitalWrite(FWREV_PIN, HIGH); - delay(10); + delay(100); + millisLeft -= 100; digitalWrite(ONOFF_PIN, HIGH); - delay(OPEN_DELAY); + while ((digitalRead(DOOR_CONTACT_1_PIN) == LOW) && (millisLeft > 0)) { + delay(100); + millisLeft -= 100; + } + delay(200); digitalWrite(ONOFF_PIN, LOW); delay(10); digitalWrite(FWREV_PIN, LOW); @@ -126,7 +136,7 @@ case INITIALIZE: digitalWrite(TEMP_SUPPLY_PIN, HIGH); delay(500); - if (digitalRead(DOOR_CONTACT_PIN) == LOW) { + if (digitalRead(DOOR_CONTACT_2_PIN) == LOW) { raiseDoor(); } DPRINTLN("-> WAIT_FOR_LIGHT");