25 lines
564 B
C++
25 lines
564 B
C++
const int lightDelay = 90000;
|
|
const byte movePin = 3;
|
|
const byte relayPin = 4;
|
|
long lastmoveMillis = 0;
|
|
|
|
void setup() {
|
|
pinMode(movePin, INPUT);
|
|
pinMode(relayPin, OUTPUT);
|
|
digitalWrite(relayPin, HIGH);
|
|
}
|
|
|
|
void loop(){
|
|
if (digitalRead(movePin) == 1) lastmoveMillis = millis();
|
|
delay(100);
|
|
if (lastmoveMillis > 0) activateRelay();
|
|
}
|
|
|
|
void activateRelay() {
|
|
if ((millis() - lastmoveMillis) < lightDelay) digitalWrite(relayPin, LOW);
|
|
if ((millis() - lastmoveMillis) > lightDelay) {
|
|
digitalWrite(relayPin, HIGH);
|
|
lastmoveMillis = 0;
|
|
}
|
|
}
|