how can i fix the following code?

int led1=13; int led2=12;

int led2state=LOW;

void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); }

void loop() { digitalWrite(led1,HIGH); delay(1000); digitalWrite(led1,LOW); delay(1000); if (led1==LOW) {led2state==HIGH;} }

i am trying to write code that when one led is on the other becomes off, and vice versa.

int led1=13; int led2=12;

int led1state=HIGH; int led2state=LOW;

void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); }

void loop() { digitalWrite(led1,led1state); delay(1000); digitalWrite(led1,led1state=LOW); delay(1000); if (led1state=LOW) { led2state=HIGH; digitalWrite(led2,led2state); }

}

here is the new code, i still don't know why it doesn't work.

Hint: = is an assigment, == is a test.

This should do what you want.

const int led1 = 13;
const int led2 = 12;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}

void loop()
{
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
delay(1000);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
delay(1000);
}

Or, a nice way to invert the states:

const int led1 = 13;
const int led2 = 12;

bool led1state = HIGH;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}

void loop()
{
 digitalWrite(led1, led1state);
 digitalWrite(led2, !led1state);
 led1state = !led1state;
 delay(1000);
}