Summing Digital Inputs - Arduino UNO

Hello folks,

I have two 45% duty cycle digital pulse trains (180 deg out of phase from one another, each of the same Hz) as inputs and would like them to be added and subsequently output (i.e. the output should look like a 90 % duty cycle digital pulse train of twice the Hz as the inputs). There is a great deal of other hardware involved and, without going into it, it that essentially prevents using the arduino as the primary clock/counter. The only thing the arduino has to do is apply the logic to the two inputs. I previously had these operations done on an instrumentation amplifier, but it delays the output by enough time to matter, especially with higher frequencies (e.g. ~>24 Hz inputs). I am hoping the arduino will be able to succeed where the amp failed.

My first approach:
*note that I call the inputs LEDs because the pins are connected to other hardware that also sends pulses to LEDs

int LED1 = 5;            //LED1 connected to pin 5
int LED2 = 7;            //LED2 connected to pin 7
int cam = 9;             //cam connected to pin 9

void setup()
{
  pinMode(LED1,INPUT);   //LED1 (pin 5) is a digital input
  pinMode(LED2,INPUT);   //LED1 (pin 7) is a digital input
  pinMode(cam,OUTPUT);   //LED1 (pin 9) is a digital output
}

void loop()
{
  if (digitalRead(LED1 == HIGH))
  {
    if (digitalRead(LED2 == LOW))
    {
      digitalWrite(cam,HIGH);
    }
  }
  if (digitalRead(LED1 == LOW))
  {
    if (digitalRead(LED2 == LOW))
    {
      digitalWrite(cam,LOW);
    }
    if (digitalRead(LED2 == HIGH))
    {
      digitalWrite(cam,HIGH);
    }
  }
}

My second approach:

const int led1 = 5;            //led1 connected to pin 5
const int led2 = 7;            //led2 connected to pin 7
const int cam = 9;             //cam connected to pin 9

int led1State = 0;
int led1StateLast = 0;
int led2State = 0;
int led2StateLast = 0;

void setup()
{
  pinMode(led1,INPUT);   //led1 (pin 5) is a digital input
  pinMode(led2,INPUT);   //led1 (pin 7) is a digital input
  pinMode(cam,OUTPUT);   //led1 (pin 9) is a digital output
}

void loop()
{
  led1State = digitalRead(led1);
  
  if (led1State != led1StateLast)
  {
    if (led1State == HIGH)
    {
      digitalWrite(cam,HIGH);
    }
    else
    {
      digitalWrite(cam,LOW);
    }
  }
  led1StateLast = led1State;

  led2State = digitalRead(led2);
  if (led2State != led1StateLast)
  {
    if (led2State == HIGH)
    {
      digitalWrite(cam,HIGH);
    }
    else
    {
      digitalWrite(cam,LOW);
    }
  }
  led2StateLast = led2State;
}

Thank you in advance for your help and I apologize if this topic has already been covered - a brief search did not uncover anything, but perhaps I am not well enough aware of the appropriate terminology.

Cheers,
GAW

If the 2 inputs really are out of phase with each other and 45% duty cycle, then they can never both be in the active state together. Therefore, if the inputs are active high (i.e. high for 45% of the time), your loop can just be this:

loop()
{
   digitalWrite(cam, digitalRead(LED1) || digitalRead(LED2));
}

If the inputs are active low, then use && instead of ||.

However, you don't need an Arduino to do this, just a logic gate, e.g. CMOS 4000 series.

Aha! Boolean operators - that's what I was looking for. Thank you very much for the guidance and the hardware suggestion! The boolean setup worked fine on the arduino, going to try with an OR gate later.