How to toggle an output when either of 2 inputs changes state?

I’ve been struggling with this for day and I can’t figure it out so I was hoping someone could give me an idea on how to do this:

I have 2 digital inputs and 1 digital output. Whenever EITHER of the digital inputs changes state (low to high or high to low) I want to toggle the output (low to high or high to low).

So for example:

To start:
In1 = L and In2 = L .... OP = L
Toggle In1 so that:
In1 = H and In2 = L .... OP = H (Output Toggles)
Toggle In2 so that:
In1 = H and In2 = H .... OP = L (Output Toggles)
And so on...

What have you tried? Post your complete sketch and people can help you.

Inside the IDE, have a look at the StateChangeDetection example (File->examples->02.digital->StateChangeDetection) to see how you can keep track of the current state of an input so you know when it changes.

Also, what are your digital inputs? Buttons? Switches? How are they wired up? You have to make sure they are wired up correctly. There is also a Button example to look at.

Test each input separately. If either input changes state (I assume that you know how to determine that ***) then set a boolean, let's name it changedState to true. After the tests, if changedState is true then change the state of the output and set changedState to false to start the process again

*** If not then see the StateChangeDetection example in the IDE

Use the forum Google search function in the upper right of this page to search for "toggle" and similar key words. You will probably find many previous project discussions and code using toggle functions.

Thanks guys, I did a bit more reading. My input right now is a toggle switch that changes high to low and vice versa but in the final implementation it will regular digital input (high or low).

Here is a simplified version of the code (I got rid of the second switch for now). It kind if works but not quite right...

If I start the arduino with the input LOW and then switch it to HIGH, the output follows - goes from LOW to HIGH. Then when I toggle the input back to LOW the output also goes LOW.

What I need is that when the arduino starts the output is LOW (whether the input is LOW or HIGH) but when the input toggles I want the output to go HIGH.

if (digitalRead(rf) == 1) {
rfstate = 1;
}
else if (digitalRead(rf) == 0) {
rfstate = 0;
}
Serial.print(rfstate);
Serial.println(prevrfstate);  
if (rfstate != prevrfstate) { // switch toggled 
prevrfstate = rfstate;  
digitalWrite(out, rfstate);
rfstate = prevrfstate;
}

I imagine that it's probable really simple and I feel bad that I can't figure it out...

Please post your whole program

What I need is that when the arduino starts the output is LOW (whether the input is LOW or HIGH)

OK. Make sure that you use digitalWrite() to set the output pin LOW at startup.

but when the input toggles I want the output to go HIGH.

Then, to get the output to toggle on every input state change from that point forward, you can use

digitalWrite(outputPin, !digitalRead(outputPin))

Ok, so I modified the State Change Detection (Edge Detection) sketch and now it does what I want it to do...
No matter whether the input is high or low when the Arduino starts, the output will start low and change to high when the input changes to its opposite level.

No, I need to expand the sketch so that it works with two inputs...

Here is the sketch so far:

// this constant won't change:
const int  switchPin = 3;    // the pin that the switch is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int switchState;         // current state of the switch
int lastswitchState = 0;     // previous state of the switch
int outState = 0;

void setup() {
  // initialize the switch pin as a input:
  pinMode(switchPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

switchState = digitalRead(switchPin);
if (switchState == HIGH) {   
  lastswitchState = switchState;
}
else {
lastswitchState = LOW;    
}
}


void loop() {
  // read the switch input pin:
  switchState = digitalRead(switchPin);

  // compare the switchState to its previous state
  if (switchState != lastswitchState) {
     if (outState == LOW) {
//     Serial.println("on");
     outState = 1;
    }
    else {
//    Serial.println("off");
    outState = 0;
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastswitchState = switchState;


  if (outState == 1) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }

}

Once a state change is detected by if (switchState != lastswitchState) , somewhere inside the brackets set a boolean flag to true. The toggle code will monitor these flags. When either is true execute the toggle. Inside the toggle code reset the flags to false.