Changing funcation depending on state?

Hi everybody. What I'm trying to do is to make a "button" (I'm using IR so effectively it would be "if a certain code is received") that will turn an led on if it is off and turn it off if it is on. In other words, to turn your TV on and off, you use the same button, but the button changes functions depending on whether the TV is on or off. Here's what I have so far(its not working, BTW):

if (CODE == POWER){
    if (ledPin3 == LOW){
      digitalWrite(ledPin3, HIGH);
    }
    if (ledPin3 == HIGH){
      digitalWrite(ledPin3, LOW);
    }

It's not working because you are comparing a pin number to the state that the pin is in. Is this apple equal to that banana? There are no definitions of apples that equal any definitions of bananas.

You need to keep track of the state that you last set the pin to, and set the new state accordingly?

Thanks for the reply. I made the turning on of the led change the value of a variable. The led can only turn on if the variable is a certain value.

  if (CODE == power){
      if (x == 0){
        digitalWrite(ledPin1, HIGH);
        digitalWrite(ledPin2, HIGH);
        digitalWrite(ledPin3, HIGH);
        x = 1;
      }


        else{
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin3, LOW);
          x = 0;
        }
      }

I ended up using this to control 3 leds. The only thing is that if you use this to turn the leds on, then turn them off manually, you have to push power twice for the variable to be readjusted. Any suggestions?

How are you turning them off "manually", is this via a switch attached to the arduino or some other way outside the arduino? If using a switch to the arduino, you can set the (variable x) accordingly.

Just a note, a variable name like powerStatus would be better than x unless you plan to keep your code down to only a few lines. Even then, best practice to start using real variable names if you plan to program much.

Best of luck.