do you know how to control the windows and detect the opening and closing of the door ?
you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction
The code could look like this (typed here, fully untested)
const byte doorPin = 2; // the switch detecting the door opening
const unsigned long durationGoingDown = 500ul; // ms
const unsigned long durationGoingUp = 1000ul; // ms
unsigned long startTime;
enum {IDLE, WINDOW_GOING_DOWN, WINDOW_DOWN, WINDOW_GOING_UP} state = IDLE;
void openWindow() {
Serial.println("activating window's motor down");
}
void stopWindow() {
Serial.println("stopping the window's motor");
}
void closeWindow() {
Serial.println("activating window's motor up");
}
void setup() {
pinMode(doorPin, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
switch (state) {
case IDLE:
if (digitalRead(doorPin) == LOW) { // door just opened
startTime = millis();
openWindow();
state = WINDOW_GOING_DOWN;
}
break;
case WINDOW_GOING_DOWN:
if (millis() - startTime >= durationGoingDown) {
stopWindow();
state = WINDOW_DOWN;
}
break;
case WINDOW_DOWN:
if (digitalRead(doorPin) == HIGH) { // door just closed
startTime = millis();
closeWindow();
state = WINDOW_GOING_UP;
}
break;
case WINDOW_GOING_UP:
if (millis() - startTime >= durationGoingUp) {
stopWindow();
state = IDLE;
}
break;
}
}