| |
---|
| | #else |
---|
| | #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 |
---|
| | #define LOWER_DOOR 2 |
---|
| |
---|
| | |
---|
| | #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]; |
---|
| | int state = WAIT_FOR_LIGHT; |
---|
| |
---|
| | |
---|
| | 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); |
---|
| | digitalWrite(ONOFF_PIN, LOW); |
---|
| |
---|
| | digitalWrite(FWREV_PIN, LOW); |
---|
| | 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; |
---|
| | } |
---|
| | delay(200); |
---|
| |
---|
| | digitalWrite(TEMP_SUPPLY_PIN, LOW); |
---|
| | } |
---|
| | |
---|
| | 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); |
---|
| | digitalWrite(TEMP_SUPPLY_PIN, LOW); |
---|
| |
---|
| | switch (state) { |
---|
| | 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"); |
---|
| | state = WAIT_FOR_LIGHT; |
---|
| |
---|
| | |