diff --git a/chicken_door.ino b/chicken_door.ino index 439049f..e9a5f11 100644 --- a/chicken_door.ino +++ b/chicken_door.ino @@ -25,12 +25,12 @@ #define INITIALIZE 0 #define WAIT_FOR_LIGHT 1 -#define LOWER_DOOR 2 +#define OPEN_DOOR 2 #define WAIT_FOR_DARK 3 -#define RAISE_DOOR 4 +#define CLOSE_DOOR 4 #define BRIGHTNESS_SIZE 3 -#define BRIGHT_THRESHOLD 600 +#define BRIGHT_THRESHOLD 200 #define OPEN_DELAY 6400 #define MAX_CLOSE_TIME 4000 #define MAX_OPEN_TIME 4000 @@ -38,7 +38,6 @@ word brightness[BRIGHTNESS_SIZE]; int state = WAIT_FOR_LIGHT; -volatile int button_state = 0; void setup() { pinMode(ONOFF_PIN, OUTPUT); @@ -71,11 +70,7 @@ Narcoleptic.disableADC(); } -/* void pressButton() { - button_state = 1; -} */ - -void raiseDoor() { +void closeDoor() { long millisLeft = MAX_CLOSE_TIME; digitalWrite(TEMP_SUPPLY_PIN, HIGH); digitalWrite(FWREV_PIN, LOW); @@ -86,13 +81,13 @@ delay(100); millisLeft -= 100; } - delay(200); +// delay(200); digitalWrite(ONOFF_PIN, LOW); delay(10); digitalWrite(TEMP_SUPPLY_PIN, LOW); } -void lowerDoor() { +void openDoor() { long millisLeft = MAX_CLOSE_TIME; digitalWrite(TEMP_SUPPLY_PIN, HIGH); digitalWrite(FWREV_PIN, HIGH); @@ -103,7 +98,7 @@ delay(100); millisLeft -= 100; } - delay(200); + delay(250); digitalWrite(ONOFF_PIN, LOW); delay(10); digitalWrite(FWREV_PIN, LOW); @@ -137,16 +132,15 @@ digitalWrite(TEMP_SUPPLY_PIN, HIGH); delay(500); if (digitalRead(DOOR_CONTACT_2_PIN) == LOW) { - raiseDoor(); + closeDoor(); } DPRINTLN("-> WAIT_FOR_LIGHT"); state = WAIT_FOR_LIGHT; break; case WAIT_FOR_LIGHT: - if ((readBrightness() > (BRIGHT_THRESHOLD + HYSTERESIS)) || (button_state == 1)) { - button_state = 0; - DPRINTLN("-> LOWER_DOOR"); - state = LOWER_DOOR; + if (readBrightness() > (BRIGHT_THRESHOLD + HYSTERESIS)) { + DPRINTLN("-> OPEN_DOOR"); + state = OPEN_DOOR; } else { #ifdef DEBUG delay(10000); @@ -155,16 +149,15 @@ #endif } break; - case LOWER_DOOR: - lowerDoor(); + case OPEN_DOOR: + openDoor(); DPRINTLN("-> WAIT_FOR_DARK"); state = WAIT_FOR_DARK; break; case WAIT_FOR_DARK: - if ((readBrightness() < (BRIGHT_THRESHOLD - HYSTERESIS)) || (button_state == 1)) { - button_state = 0; - DPRINTLN("-> RAISE_DOOR"); - state = RAISE_DOOR; + if (readBrightness() < (BRIGHT_THRESHOLD - HYSTERESIS)) { + DPRINTLN("-> CLOSE_DOOR"); + state = CLOSE_DOOR; } else { #ifdef DEBUG delay(10000); @@ -173,8 +166,8 @@ #endif } break; - case RAISE_DOOR: - raiseDoor(); + case CLOSE_DOOR: + closeDoor(); DPRINTLN("-> WAIT_FOR_LIGHT"); state = WAIT_FOR_LIGHT; break;