Help about loops

I have an "if" inside another "if". The first one is in the void loop, so is always active, but how do i loop the second one too? (For it to be always active)

A decision instruction that loops is the while structure. Is that what you mean? If not, please show in plain language (psuedo code) what you are trying to do.

void loop() {
b:
lcd.setCursor(0,0);
lcd.print(valor);
lcd.setCursor(3,0);
lcd.print("HORAS / RIEGO");
en= digitalRead(boton);
ap= digitalRead(botond);
Serial.println(valor);
pot = analogRead(0);
valor = map(pot, 0, 1019, 1, 48);
if(en==1){
a:
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");
digitalWrite(led,HIGH);
delay(300);
digitalWrite(led,LOW);
if(millis()-t>15000){ //this is the if i can´t loop

}

}

Put it outside the first 'if'.

I cant´t. The second if depends of the fist one...

The body on the if structure is empty. What is supposed to happen if the if is true? What is supposed to happen if the if is false?

Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

void loop() {
serv.write(180);
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, 1, 48);
if(en==1){
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");
while (millis()>15000){
digitalWrite(led,HIGH);
}

The thing is that when i put something inside the structure, it doesn´t work, because there is not a loop to constantly check if the "if" is true.

HORAS HOURS
RIEGO IRRIGATION
ACTIVADO ACTIVATED

Anyway, 15 seconds into your program this, if executed

while (millis() > 15000) {
  digitalWrite(led, HIGH);
}

will turn on the LED (I assume you've wired it that way) and hang for… ever.

Please describe what you trying to do and we can work backwards (!) from that.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.