If/Else Statements; How Do I Specify Multiple Actions?

Hi All,

I'm having a few issues with If/Else statements with my Arduino and am hoping that you guys (and girls) can help.

I am building an aquarium monitoring system (comprising of temperature, level and filter flow rate information displayed on an LCD display and text messaging should any parameter go outside of specification) and my issue is this:

I have an If/Else statement to evaluate a digital input from a level sensor, the idea is that if the input is high (i.e. the tank level is within spec.) then the LCD backlight is switched off and 'Level:OK' is displayed. In the event that the input goes low (i.e. the tank level has dropped and is now out of spec.) the backlight is switched on, "Level:Low" is displayed and the system sends a text message.

I'm not concerned about the text messaging part yet (starting with the basics!) but am struggling to specify two actions in an If statement (code follows):

//Level Sense

lcd.clear();
lcd.setCursor(6,1);

if (digitalRead(buttonPin) == LOW)
//lcd.print("Low")
digitalWrite(LcdBackLight, HIGH);

else

//lcd.print("OK");
digitalWrite(LcdBackLight, LOW);

(code ends)

lcd.print is currently commented out however the digitalWrite portion works okay; if I comment out the digitalWrite the lcd.print portion works okay - the plan is to have both the lcd.print & digitalWrite actions take place for each condition.

Hopefully that all makes sense and I would welcome any tips or advice offered as this is now driving me crazy!

Thanks

Dan

Braces.

  if (digitalRead(buttonPin) == LOW)
  {
    lcd.print("Low")
    digitalWrite(LcdBackLight, HIGH);
  }
  else
  {
    lcd.print("OK");
    digitalWrite(LcdBackLight, LOW);
  }

Fantastic!

Thank you very much for the quick response - now works like a charm :slight_smile:

Dan

Any time you have a conditional executes several statements you use the braces to identify the statements that are attached to that condition. Just in case you didn't pick that up. It applies to any conditional or looping comands.