Little help on 'if' commands (LCD serial)

Right, before I start I got this code from the arduino page. I have tried to edit it so i can switch some inputs on and off etc.

So I find this proggraming language really difficult and if any one can recomend me a cook to learn C a lot better (for arduino) please let me know. I am currently reading 30 arduino projects for the evil genius and it doesnt really teach you the programming side :/.

here we go, My code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);


void setup(){
    // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(115200);
  pinMode(9,OUTPUT);
}

void loop()
{ 
 if (Serial.available()) {      
    if (Serial.read() == "1");
   {     
     digitalWrite(9,HIGH);
   }
lcd.clear();
  
    while (Serial.available() > 0) {    
      lcd.write(Serial.read());
    }
}

Like I said I got it from here: http://arduino.cc/en/Tutorial/LiquidCrystalSerial

and I just want it so that if i send the number 1 over serial it turns the back light on (for the LCD) and if any one can be a really nice person could they also include a if statement of the number 0 it turns it off? :slight_smile: It would be really awesome and thank you for taking a look. The problem at the moment is I get the error codes: LCD_example.cpp:
In function ‘void loop()’:
LCD_example.pde:-1: error: ISO C++ forbids comparison between pointer and integer
LCD_example.pde:-1: error: expected `}’ at end of input

Thanks again :slight_smile:

    if (Serial.read() == "1");

The Serial.read function returns a byte, or character. That single character will NEVER equal a string.

I'm nearly certain that the example in the book did not have a semicolon on the end of the if statement, either.

if(Serial.read() == '1')

would work a lot better.

trevorboultwood: if (Serial.available()) {          if (Serial.read() == "1");    {           digitalWrite(9,HIGH);    }

Serial.read() is returning a character value, but "1" is the address of a character array with a 1 in it. Change to single quotes should do the job here:

 if (Serial.available()) {      
    if (Serial.read() == '1');
   {     
     digitalWrite(9,HIGH);
   }