// Seguidor Solar
#include <Servo.h>
//Definiendo Servomotor
Servo servo1;
int servomotor = 0;
int servomotorLS = 160;
int servomotorLI = 20;
//Asigando fotoresisenticas
int fsup = 0; // Fotoresistencia superior
int finf = 1; // Fotoresistencia inferior
void setup (){
motor.attach(3);
servo1.attach(9);
servo1.write(0);
delay(500);
}
void loop()
{
servomotor = servo1.read();
//Entradas de valores de las fotoresistencias
int sup = analogRead(fsup);
int inf = analogRead(finf);
if (sup < inf)
{
servo1.write(servomotor +1);
if (servomotor > servomotorLS)
{
servomotor = servomotorLS;
}
delay(10);
}
else if (inf < sup)
{
servo1.write(servomotor -1);
if (servomotor < servomotorLI)
{
servomotor = servomotorLI;
}
delay(10);
}
else
{
servo1.write(servomotor);
}
delay(10);
}
void AbrirPuerta(){
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
motor.write(9);
delay(500);
motor.write(20);
delay(500);
motor.write(30);
delay(500);
motor.write(40);
delay(500);
motor.write(50);
delay(500);
motor.write(60);
delay(500);
motor.write(70);
delay(500);
motor.write(80);
delay(500);
motor.write(90);
delay(500);
motor.write(100);
delay(500);
motor.write(110);
delay(500);
motor.write(120);
delay(500);
motor.write(130);
delay(500);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(5000);
}
void CerrarPuerta(){
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
motor.write(130);
delay(500);
motor.write(120);
delay(500);
motor.write(110);
delay(500);
motor.write(100);
delay(500);
motor.write(90);
delay(500);
motor.write(80);
delay(500);
motor.write(70);
delay(500);
motor.write(60);
delay(500);
motor.write(50);
delay(500);
motor.write(40);
delay(500);
motor.write(30);
delay(500);
motor.write(20);
delay(500);
motor.write(10);
delay(500);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
}