Paso 8: código
#include < Servo.h >Servo myservo;
int pos = 0;
int calibrationTime = 30;
tiempo unsigned int lowIn;
pausa larga unsigned int = 5000;
Boolean lockLow = true;
takeLowTime Boolean;
pirPin INT = 12;
pirPos int = 13;
void setup() {}
myservo.Attach(4);
Serial.Begin(9600);
pinMode (pirPin, entrada);
pinMode (pirPos, salida);
digitalWrite (pirPos, HIGH);
Serial.println ("calibración sensor");
para (int i = 0; i < calibrationTime; i ++) {}
Serial.Print(calibrationTime-i);
Serial.Print("-");
Delay(1000);
}
Serial.println();
Serial.println("Done");
mientras que (digitalRead(pirPin) == HIGH) {}
Delay(500);
Serial.Print(".");
}
Serial.Print ("SENSOR activo");
Delay(1000);
}
void loop() {}
if(digitalRead(pirPin) == HIGH) {}
para (pos = 0; pos < 180; pos += 1)
{
myservo.Write(POS);
Delay(5);
}
para (pos = 180; pos > = 1; pos-= 1)
{
myservo.Write(POS);
Delay(5);
}
{if(lockLow)}
lockLow = false;
Serial.println("---");
Serial.Print ("movimiento detectado en");
Serial.Print(Millis()/1000);
Serial.println ("sec");
Delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW) {}
{if(takeLowTime)}
lowIn = millis();
takeLowTime = false;
}
Si (! lockLow & & millis() - lowIn > pausa) {}
lockLow = true;
Serial.Print ("movimiento terminada en");
Serial.Print((Millis() - pausa) / 1000);
Serial.println ("sec");
Delay(50);
}
}
}