reading separate inputs on digital pins, storing order and replaying as output

I’m sure I’m missing something very simple here, but I’ve hit a wall with my first project.

What I’m trying to achieve:
Set pins A, B, C, D, and E as inputs
Have arduino read the state of 3 digital pins: A, B, and C
Listen for a total of 5 separate inputs on those 3 pins that can be either a single pin, or two pins simultaneously, store order of inputs
After 5 inputs are received, set pins A, B, and C to outputs
Play back sequence on pins A, B, and C upon receiving an input to pin D, flash LED upon input to pin E

I have global variables to “store” the inputs and assign the possible output types:

int firstInput;
int secondInput;
int thirdInput;
int fourthInput;
int fifthInput;
int currentInput;
int inputCount;
int combo1() {
  digitalWrite(A, HIGH);
  press();
  off();
  wait();
}
int combo2() {
  digitalWrite(A, HIGH);
  digitalWrite(C, HIGH);
  press();
  off();
  wait();
}
int combo3() {
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  press();
  off();
  wait();
}
int combo4() {
  digitalWrite(B, HIGH);
  press();
  off();
  wait();
}
int combo5() {
  digitalWrite(C, HIGH);
  press();
  off();
  wait();
}
const int press() {  // HOW LONG OUTPUT IS ON
  delay(100);
}
const int wait() {  // HOW LONG TO WAIT BETWEEN OUTPUTS
  delay(50);
}
const int off() {   // RETURN OUTPUTS TO "OFF" STATE
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);

here is my setup and main loop (and where I think part of my problem is)

void setup() {
  inputCount = 0;
  pinMode(D, INPUT);
  pinMode(E, INPUT);
  digitalWrite(D, HIGH); // TURN ON PULL UPS
  digitalWrite(E, HIGH);
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
}
void loop() {
  while (inputCount < 5) {
    digitalWrite(LED, HIGH); // TURN ON AN LED TO LET ME KNOW IT'S STILL IN LEARN ROUTINE
    currentInputLearn(); // CALL INPUT LEARN FUNCTION
  }
  if (inputCount == 5) { // IF LEARN ROUTINE IS COMPLETE CARRY ON MAIN LOOP
    digitalRead(D);
    digitalRead(E);
    if (digitalRead(D) == LOW) { // IF D IS LOW, OUTPUT LEARNED COMBINATION, (THIS IS WHERE I THINK PART OF MY PROBLEM IS)
      firstInput;
      secondInput;
      thirdInput;
      fourthInput;
      fifthInput;
    }
    else {
      off();
    }
    if (digitalRead(E) == LOW) {
      digitalWrite(LED, HIGH)
    }
  }
}

here is my input learning function

int currentInputLearn() {      // ASSIGN WHICH POSITION IS CURRENTLY BEING LEARNED
  digitalWrite(A, LOW);  // TURN ON PULL DOWNS
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  pinMode(A, INPUT);  // SET A, B, AND C TO INPUTS TO LEARN CODE
  pinMode(B, INPUT);
  pinMode(C, INPUT);
  if (inputCount == 0) {
    currentInput = firstInput;
    learn();
  }
  else if (inputCount == 1) {
    currentInput = secondInput;
    learn();
  }
  else if (inputCount == 2) {
    currentInput = thirdInput;
    learn();
  }
  else if (inputCount == 3) {
    currentInput = fourthInput;
    learn();
  }
  else if (inputCount == 4) {
    currentInput = fifthInput;
    learn();
  }
  else if (inputCount == 5) { // IF INPUT LEARN ROUTINE IS DONE, SET PINS A, B, AND C BACK TO OUTPUTS
    pinMode(A, OUTPUT);
    pinMode(B, OUTPUT);
    pinMode(C, OUTPUT);
  }
}
int learn() {      // MAIN INPUT LEARN FUNCTION
  unsigned long startPress = 0; // THIS IS RELATED TO MAKING SURE AN INPUT IS ONLY ACCEPTED IF IT IS HELD FOR A CERTAIN TIME
  while (inputCount < 5) {
    digitalRead(A);
    digitalRead(B);
    digitalRead(C);
    if (digitalRead(A) == LOW && digitalRead(B) == LOW && digitalRead(C) == LOW) {
      startPress = 0;
    }
    else {
      if (startPress == 0) {
        startPress = millis();
      }
      else if (millis() - startPress > 1000) {
        if (digitalRead(A) == HIGH && digitalRead(B) == LOW && digitalRead(C) == LOW) {
          currentInput = combo1();
          learnBlink();  // BLINKS THE LEARN LED AS A VISUAL INDICATOR THAT INPUT WAS ACCEPTED, AMOUNT OF BLINKS INDICATES WHAT INPUT WAS READ
          delay(1000);
          inputCount++;
        }
        if (digitalRead(A) == HIGH && digitalRead(B) == LOW && digitalRead(C) == HIGH) {
          currentInput = combo2();
          learnBlink();
          learnBlink();
          delay(1000);
          inputCount++;
        }
        if (digitalRead(A) == HIGH && digitalRead(B) == HIGH && digitalRead(C) == LOW) {
          currentInput = combo3();
          learnBlink();
          learnBlink();
          learnBlink();
          delay(1000);
          inputCount++;
        }
        if (digitalRead(A) == LOW && digitalRead(B) == HIGH && digitalRead(C) == LOW) {
          currentInput = combo4();
          learnBlink();
          learnBlink();
          learnBlink();
          learnBlink();
          delay(1000);
          inputCount++;
        }
        if (digitalRead(A) == LOW && digitalRead(B) == LOW && digitalRead(C) == HIGH) {
          currentInput = combo5();
          learnBlink();
          learnBlink();
          learnBlink();
          learnBlink();
          learnBlink();
          delay(1000);
          inputCount++;
        }
      }
    }
  }
  if (inputCount == 5) {
    digitalWrite(13, LOW); // TURN LED OFF AS VISUAL INDICATOR LEARN ROUTINE IS OVER
  }
}

After uploading it to my arduino, the learn routine LED comes on and blinks accordingly to indicate the input combinations (INPUT A, INPUTS A&C, etc.)
Once 5 inputs are accepted, the LED turns off
If I set input E to low, the LED comes on as expected, however if I set pin D to low, nothing happens.

My thoughts are that I have something screwed up in the main loop as to how it’s calling the “recorded” inputs to playback or I am not correctly associating the inputs to a variable when I’m “recording” them in the learn() function.

It likely isn’t relevant, but I can get the arduino to output a correct combination of A, B and C if I manually write the sequence in the code, however I want the arduino to learn the sequence from the user, then play it back in the same order. The playback output durations will be fixed, so only the order is necessary to be “learned/recorded”.

I appreciate any help.

Can you post a schematic, how can your circuit be an input and an output at the same time.

    digitalRead(D);
    digitalRead(E);

This doesn't achieve anything. You need to store the results, eg.

  a = digitalRead(D);
  b = digitalRead(E);

      firstInput;
      secondInput;
      thirdInput;
      fourthInput;
      fifthInput;

What does that do?

Grumpy_Mike:
Can you post a schematic, how can your circuit be an input and an output at the same time.

does this help?

(see attached)

thanks for the feedback on digitalReads Nick Gammon.

as for

      firstInput;
      secondInput;
      thirdInput;
      fourthInput;
      fifthInput;

well this currently appears to do nothing well at least not what I had hoped… what I want to do is output the inputs firstInput, secondInput, etc. in the order shown, I want this part of the code to determine the order of the output.

Does this make sense? I want this to learn a combination entered from 5 switches that produces inputs on 3 inputs, depending on the buttons pressed (see attached schematic for hopefully an idea of what I’m getting at).
Once the combination is learned, I want the arduino to output the combination upon receiving a single momentary input on D.

Thanks for the help, like I said, this is my first real arduino project and I’m lucky I’ve made it this far.

arduinoSchem.png

what I want to do is output the inputs firstInput, secondInput, etc. in the order shown,

You may want that, but you have no "action" there. You may as well say "apple". Do you want to eat the apple, cook it, buy it, sell it etc?

Maybe you mean:

digitalWrite (firstInput, HIGH);

or:

digitalWrite (firstInput, LOW);

Then you are doing something with it.

Although you probably don't want to write to the input.

You may need to clarify what you are trying to do here. Your code doesn't seem to match your expectations. Perhaps experiment with a simpler bit of code to get the hang of the relationship between digitalRead, digitalWrite, etc.

When the code shows "firstInput" etc, in the main loop, my goal is to call the function that was associated with that variable during the learn() function. So if during learn, input A went high and the counter was at 0, the goal was to associate firstInput with the combo1() function. Does that make sense?

So the code if during learn the input was A, A, A&B, A, C..

The code
firstInput;
secondInput;
thirdInput;
fourthInput;
fifthInput;

Would actually call
combo1();
combo1();
combo3();
combo1();
combo5();

Does this help illustrate my goal? I understand what I wrote may not accomplish what I'm trying to do, this is why I'm asking for guidance of the best way to approach the situation.

I suggest you post all your code. The way you define things like A will influence the answer.

That circuit can destroy your arduino. If you output low and someone pushes the put ton then you will blow the output pin of the chip.