[Help Please] void returns true even when false

So I'm trying to make a void that turns a LED on or off if I call it with 1 or 0 but it always turns the LED on even if I tell it 0.
Code:

pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);

digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);

Serial.begin(9600);
}

void loop(){
A1LED(1);
//digitalWrite(9, HIGH);
//digitalWrite(11, LOW);
delay(500);

A1LED(0);
//digitalWrite(9, LOW);
//digitalWrite(11, HIGH);
delay(500);

}

void A1LED(int x)
{
if(x = 1)
{
digitalWrite(9, HIGH);
digitalWrite(11, LOW);
Serial.println("True");
}
else
{
digitalWrite(9, LOW);
digitalWrite(11, HIGH);
Serial.println("False");
}
}

// change this
 if(x = 1)
// to this
 if(x == 1)

I'm trying to make a void

No you are not. You are trying to make a void function, ie one that does not return a value as opposed to one that returns a value in which case the type of variable returned would form part of the function definition rather than void.

If you saw this function

int doubleTheNumber(int x)
{
  return x * 2;
}

would you call in an int ?

Thanks >.> I forgot its == in C (im used to VB.net)

SabreToothLeopard:
Thanks >.> I forgot its == in C (im used to VB.net)

That is why I have been trying to remember to use "if (5 == x) " for example - if you forget the second "=" sign, the compiler will throw it out because you are assigning a variable to a literal. I've been bitten by that one myself a few times - " if (x=5)" not only is always true, but it assigns "5" to "x". Write it backwards and let the compiler help you :slight_smile:

Yoda conditions :slight_smile: It's handy they throw an error when you forget a "=" but I still feel like, uhm yes, speaking to Yoda...

septillion:
Yoda conditions :slight_smile: It's handy they throw an error when you forget a "=" but I still feel like, uhm yes, speaking to Yoda...

Agree with you I must :slight_smile: