Vale, me ha surgido otra duda. Ya se como hacer lo del tiempo. La persiana tarda aproximadamente 18 segundos en subir o bajar. Para probar he creado el primer movimiento que haría por la mañana, que seria subirse durante 6 segundos. Voy a mantener el interruptor que venia con la persiana:

El neutro va conectado al motor y la fase pasa por el interruptor que cambia entre parado, subir y bajar.
El interruptor lo voy a desconectar y conectarlo a arduino. El Rele1 activa y desactiva el motor y el Rele2 selecciona el sentido de giro.
Actualmente me mueve la persiana según la ldr y la NTC (resistencia térmica) y manualmente cuando pulso un botón. Ahora va mi problema. El valor Posicion es donde se encuentra la persiana, abajo es 0 y arriba es 20 (Son segundos). si la persiana se mueve automáticamente funcionaria bien, pero cuando la muevo manualmente necesito que también cambie el valor Posicion. Para eso he intentado usar la función pulseIn que en teoría mide el tiempo que esta un botón pulsado. si pudiese medir el tiempo que subo la persiana manualmente se lo podría sumar al valor Posicion y saber donde esta aunque la controle de forma manual. El problema es que no consigo hacer funcionar pulseIn.
A, lo de la automatización todavía no lo he configurado. he creado el primer movimiento que la levanta por la mañana 6 segundos para probar si funciona. Cuando tenga el resto completo creare todos los movimientos automáticos Este es el que he creado:
if (Posicion == 0)
{
if (NTCValue <= 200)
{
if (LDRValue > 100)
{
Posicion =+ 6;
digitalWrite(Rele1, HIGH);
digitalWrite(Rele2, LOW);
delay(6000);
digitalWrite(Rele1, LOW);
digitalWrite(Rele2, LOW);
}
}
Este es el desastre que tengo por código en el que se que es una burrada la forma en la que he intentado usar pulseIn. Los comentarios no están la mayoría bien puestos, como estoy modificando algunos son incorrectos.
int LDR = A0; // select the input pin for the LDR
int NTC = A1; // select the input pin for the NTC
int Down = 12; // select the input pin for the down button
int Up = 13; // select the input pin for the up button
int Rele1 = 2; // select the pin 2 for the Rele 1
int Rele2 = 3; // select the pin 3 for the Rele 2
int Led = 4; // select the pin 4 for the Led
int LDRValue = 0; // variable to store the value coming from the LDR
int NTCValue = 0; // variable to store the value coming from the LDR
int DownValue = 0; // variable to store the value coming from the LDR
int UpValue = 0; // variable to store the value coming from the LDR
int TiempoSubir = 0;
int TiempoSubiendo = 0;
int Posicion = 0; // set the position to 0
void setup() {
Serial.begin(9600);
// declare the Rele1 Pin as an OUTPUT:
pinMode(Rele1, OUTPUT);
// declare the Rele2 Pin as an OUTPUT:
pinMode(Rele2, OUTPUT);
// declare the Rele2 Pin as an OUTPUT:
pinMode(Led, OUTPUT);
digitalWrite(Rele1, HIGH);
digitalWrite(Rele2, HIGH);
digitalWrite(Led, HIGH);
delay(20000);
digitalWrite(Rele1, LOW);
digitalWrite(Rele2, LOW);
digitalWrite(Led, LOW);
digitalWrite(TiempoSubiendo, LOW);
}
void loop() {
// Leer valor de la ldr:
LDRValue = analogRead(LDR);
// Leer valor de la NTC:
NTCValue = analogRead(NTC);
// Leer valor de Down button:
DownValue = digitalRead(Down);
// Leer valor de Up button:
UpValue = digitalRead(Up);
if (Posicion >= 20)
{
Posicion = 19;
}
switch (DownValue) {
case HIGH:
//BOTON BAJAR
digitalWrite(Rele1, HIGH);
digitalWrite(Rele2, HIGH);
digitalWrite(Led, HIGH);
break;
case LOW:
switch (UpValue) {
case HIGH:
//BOTON SUBIR
digitalWrite(Rele1, HIGH);
digitalWrite(Rele2, LOW);
digitalWrite(Led, HIGH);
digitalWrite(TiempoSubiendo, HIGH);
TiempoSubir = pulseIn(TiempoSubiendo, HIGH);
break;
case LOW:
//SIN BOTONES
digitalWrite(Rele1, LOW);
digitalWrite(Rele2, LOW);
digitalWrite(Led, LOW);
digitalWrite(TiempoSubiendo, LOW);
if (Posicion == 0)
{
if (NTCValue <= 200)
{
if (LDRValue > 100)
{
Posicion =+ 6;
digitalWrite(Rele1, HIGH);
digitalWrite(Rele2, LOW);
delay(6000);
digitalWrite(Rele1, LOW);
digitalWrite(Rele2, LOW);
}
}
}
break;
}
break;
}
Serial.print("Posicion: ");
Serial.print(Posicion);
Serial.print("\t LDR:" );
Serial.print(LDRValue);
Serial.print("\t NTC:" );
Serial.print(NTCValue);
Serial.print("\t Down:" );
Serial.print(DownValue);
Serial.print("\t Up:" );
Serial.println(UpValue);
Serial.print("\t Tiempo subir:" );
Serial.println(TiempoSubir);
}
Muchas gracias si alguien ha tenido la paciencia para leer toda la reply y por la ayuda. Seguro que he explicado alguna cosa mal o de forma incompleta. Comentármelo y lo amplio.