If condition problem =S / Please Help, Urgent

i write a code that switch pin 13 on and off by sending 1 and 2

i put an if condition to show a error message when another value other than 1 or 2 is received

the problem when i open serial monitor, it keep on displaying the error message, without even writing any number yet =S

what did i do wrong? the code is written below

char val; // variable to receive data from the serial port int f = 13;

void setup() { pinMode(f = 13, OUTPUT); // pin 13 as OUTPUT Serial.begin(9600); // start serial communication at 9600bps }

void loop() { if( Serial.available() ) {;} // if data is available to read

val = Serial.read(); // read it and store it in 'val'

if( val == '1' ) { // if '1' was received, led 13 is off digitalWrite(f, LOW); // turn Off pin 13 off delay(1000); // waits for a second Serial.println("13 off"); }

if( val == '2' ) { // if '2' was received, led 13 is on digitalWrite(f = 13, HIGH); // turn ON pin 13 on delay(1000); // waits for a second Serial.println("13 on"); }

if( val != '1' || val != '2' ) { Serial.println("Error, Please enter the correct number"); } }

if( Serial.available() ) {;} // if data is available to read No you don't do it like this, you only read when serial data is available. That line of code does nothing.

char val;         // variable to receive data from the serial port
int f = 13;

void setup()
{  pinMode(f = 13, OUTPUT);    // pin 13 as OUTPUT
  Serial.begin(9600);    // start serial communication at 9600bps
 }

void loop() {
  if( Serial.available() ) {       // if data is available to read

  val = Serial.read();      // read it and store it in 'val'

  if( val == '1' ) {              // if '1' was received, led 13 is off
      digitalWrite(f, LOW);          // turn Off pin 13 off
      delay(1000);                   // waits for a second 
      Serial.println("13 off");
     }

    if( val == '2' ) {                // if '2' was received, led 13 is on
     digitalWrite(f = 13, HIGH);      // turn ON pin 13 on
     delay(1000);                     // waits for a second
     Serial.println("13 on");
    }

    if( val != '1' || val != '2' ) {
      Serial.println("Error, Please enter the correct number");
    }
  } // end of if( Serial.available()
 }

er I'm sure I just saw this in another thread?!?

one posting is enough

This is the right place please remove the other post.

Thnks alot for reply :)

w yes i posted it in another thread then i realized that this is right place to ask, other post is deleted :)

Thanks
I think the logic is screwed on this line:-
if( val != ‘1’ || val != ‘2’ )
If val is equal to 2 it will not be equal to one and will pass the condition.
So what ever value you use it will report an error.
You mean
if( !( val == ‘1’ || val == ‘2’ ) ) {

yes that's where the error is XD

i tried it and it worked :)

Thnks alot for ur help :)

so glad I took the time to reply to the other post then :(