Combine 2 inputs for an additional output

My first post so be gentle. I have no code to post as of yet. I am attempting to use a clear core controller using their arduino wrapper. I do not have enough individual inputs so my thought was to use 2 inputs that would creat an additional option. Here is the project example. I have 5 “recipes” in which will move the servos a set number of steps. Input 1 sets the step count to 2400 steps. Input 2 would set it to 3400. Input 1+2 would set it at 4400 steps etc…
My programming experience is with proprietary software from keyence, yushin, Campetella and wittmann robots. I have no c+ experience at all. Any advise would help. I am trying to understand how it works a little better before I dive into it.
Thank you in advance.

If I understand correctly you could just have one input. Use an analog input and 3 resistance values to set your step count. eg 5v, 3v, gnd. A single switch could set which value.

Thanks for the the reply. I left out an important detail. The inputs will be coming from one of the machine tending robots. It would have to be digital high/low. So each time the parts are released from the robot, it would send a high signal to the clear core. Each "recipe" would have its own outputs programmed into the robot.

How many inputs do you need?

` // Move step counts positive direction

 if (digitalRead (IO1 == HIGH)); 
 MoveDistance(2400);

 if (digitalRead (IO2 == HIGH)); 
 MoveDistance(3400);

  if (digitalRead (IO1  == HIGH)); 
 MoveDistance(4400);

  if (digitalRead (A12 == HIGH)); 
 MoveDistance(5400);

  if (digitalRead (I/O1 && A12 == HIGH)); 
 MoveDistance(6400);
 }

This is what I had in my head.` I

you have 2 conflicting bits of code there but I can't see a problem with having a conditional statement if x and y are high do something but you would need to change the other statements to have if x is high and y is low otherwise both statements would be true at the same time (where x and y are pins)

look also at state machines and switch case

That makes sense. I didn't even think about that.

     if (digitalRead (IO1 == HIGH && A12 == LOW)); 
     MoveDistance(2400);

     if (digitalRead (IO2 == HIGH)); 
     MoveDistance(3400);

      if (digitalRead (IO1 == HIGH)); 
     MoveDistance(4400);

      if (digitalRead (A12 == HIGH)); 
     MoveDistance(5400);

      if (digitalRead (IO1 && A12 == HIGH)); 
     MoveDistance(6400);
     }

Your first if and your 5th if will conflict with your 3rd if in that if either the former are active the later will also be.

I had changed it but did the copy and paste before hand.

     if (digitalRead (IO1 == HIGH && A12 == LOW)); 
     MoveDistance(2400);

     if (digitalRead (IO2 == HIGH && IO1 == LOW)); 
     MoveDistance(3400);

      if (digitalRead (IO1 && IO2 == HIGH)); 
     MoveDistance(4400);

      if (digitalRead (A12 == HIGH)); 
     MoveDistance(5400);

      if (digitalRead (IO1 && A12 == HIGH)); 
     MoveDistance(6400);
     }

wrong syntax:

     if (digitalRead (IO1 == HIGH && A12 == LOW)); 
     MoveDistance(2400);

     if (digitalRead (IO2 == HIGH)); 
     MoveDistance(3400);

The correct syntax would be

     if (digitalRead (IO1) == HIGH && digitalRead(A12) == LOW) { 
     MoveDistance(2400);
 }

     if (digitalRead (IO2) == HIGH) {
     MoveDistance(3400);
}

But, your if statements have to resolve all conflicts.

I would stick with an order rather than changing it. So if IO1 high and X high, if IO1high and x low, if io1 low and x high etc. ie do all your io1 cases first. Just for clarity

It is getting a bit repetitive and switch case/state machines can help with this and make it easier to read particularly if you are going to have more functionality/code related to each case

I changed the syntax like your example but it failed the verify operation. I removed them like it was originally and passed the verify. Could this be part of the ClearCore library?

You could use a else if there

Post the version that failed verification.

Here is the one that failed.

     if (digitalRead (IO1) == HIGH && A12 == LOW)); 
     MoveDistance(2400);

      if (digitalRead (IO1) && (IO2) == HIGH)); 
     MoveDistance(3400);
     
      if (digitalRead (IO1) == LOW && (IO2) == HIGH)); 
     MoveDistance(4400);
     
      if (digitalRead (IO1) && (A12) == HIGH)); 
     MoveDistance(5400);     

      if (digitalRead (A12) == HIGH)); 
     MoveDistance(6400);
     }


this is the error.

expected primary-expression before ')' token

Other that that Syntax discrepancy, does this look better?

     if (digitalRead (IO1 == HIGH && A12 == LOW)); 
     MoveDistance(2400);

      if (digitalRead (IO1 && IO2 == HIGH)); 
     MoveDistance(3400);
     
      if (digitalRead (IO1 == LOW && IO2 == HIGH)); 
     MoveDistance(4400);
     
      if (digitalRead (IO1 && A12 == HIGH)); 
     MoveDistance(5400);     

      if (digitalRead (A12 == HIGH)); 
     MoveDistance(6400);
     }

digitalRead(IO2)

IO2 is a pin number.

I used the example from this site.
"pinMode(pin, mode)"

You really need to learn a bit about the programming language. Please study the examples that come with the Arduino IDE to learn more about the special features of Arduino.

pinMode(pin, mode) sets up the pin as INPUT or OUTPUT.
digitalRead(pin) determines the logic level presented at the pin.

Or this; (untested)


void setup() {
  Serial.begin(115200);
}

void loop() {

  uint8_t inputVal; // interpret this value to select distance

  inputVal = 0;
  //
  // combine all the inputs into a single byte using bitWrite()*
  //
  bitWrite(inputVal, 0, digitalRead(IO1));
  bitWrite(inputVal, 1, digitalRead(IO2));
  bitWrite(inputVal, 2, digitalRead(A12));

  if (inputVal = 1) {
    // do stuff
  }

  if (inputVal = 2) {
    // do other stuff
  }

  if (inputVal = 3) {
    // do other stuff
  }
  // etc., etc., etc.
}

*Arduino Reference - Arduino Reference

//if (inputVal = 1) {
if (inputVal == 1) {
// do stuff
}