Hej!
I worked out a new code, and it works fine. Thanks for the help everybody, I probably have a question in the near future about a programming problem. But from now on I'll be fine.
[tt]int mainLightOn = 2;
int mainLightOff = 4;
boolean doorSwitch;
int LastdoorSwitch = 0;
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(mainLightOn, OUTPUT);
pinMode(mainLightOff, OUTPUT);
pinMode(doorSwitch, INPUT);
}
void loop() {
delay(1000);
doorSwitch = digitalRead(3);
Serial.println(doorSwitch);
if (doorSwitch != LastdoorSwitch) {
if (doorSwitch == LOW) {
Serial.println("Door Switch HIGH");
digitalWrite(mainLightOn, HIGH);
delay(1500);
digitalWrite(mainLightOn, LOW);
}
else if (doorSwitch == HIGH) {
Serial.println("Door Switch LOW");
digitalWrite(mainLightOff, HIGH);
delay(1500);
digitalWrite(mainLightOff, LOW);
}
}
LastdoorSwitch = doorSwitch;
}
[/tt]