// When you press the button, it is supposed to blink each 10 seconds. The first two blinks (20s) it works well, but in the third one, the light keeps on, and doesn't turn off. (Why is this?) The other button is to stop the sequence...
//LIBRERÍAS
#include <LiquidCrystal.h>
#include <Servo.h>
///////////////////////////////
LiquidCrystal lcd(7,6,5,4,3,2);
Servo serv;
//VARIABLES//
int pot; //Potenciómetro
int valor; //Valor del potenciómetro
int boton=9; //Botón de encendido
int botond=12; //Botón de apagado
int ap;
int en;
int led=13;
int t; //Tiempo
int act; //activado?
//SETUPS//
void setup() {
t =millis();
lcd.begin(16, 2);
lcd.setCursor(0,1);
lcd.print("DESACTIVADO");
pinMode(boton,INPUT);
pinMode(led,OUTPUT);
serv.attach(8);
Serial.begin(9600);
}
void loop() {
lcd.setCursor(0,0);
lcd.print(valor);
lcd.setCursor(3,0);
lcd.print("HORAS / RIEGO");
en= digitalRead(boton);
ap= digitalRead(botond);
pot = analogRead(0);
valor = map(pot, 0, 1019, 10, 48);
if(en==1){ //Botón encendido
t =millis();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(valor);
lcd.setCursor(3,0);
lcd.print("HORAS / RIEGO");
lcd.setCursor(0,1);
lcd.print("ACTIVADO");
act=1;
}
while(millis()-t> 10000){
if(act==1){
t=millis();
digitalWrite(led,HIGH);
delay(200);
digitalWrite(led,LOW);
t=millis();
}
}
if(ap==1){ //Botón apagado
digitalWrite(led,HIGH);
delay(300);
digitalWrite(led,LOW);
lcd.setCursor(0,1);
lcd.print("DESACTIVADO");
act=0;
}
}
// When you press the button, it is supposed to blink each 10 seconds. The first two blinks (20s) it works well, but in the third one, the light keeps on, and doesn't turn off. (Why is this?) The other button is to stop the sequence...