Can't get my board to read inputs from a switch and output on a 7-segment LCD.

I’m trying to read the inputs on an Uno from a thumb wheel switch, which provides 4 binary inputs. I then want the corresponding decimal number to display on a 7-segment LCD ( 0000 = 0, 0001 = 1, etc…). Each of the segments on the LCD has its own output on the Uno.

I wrote code for it which I thought would work, but it doesn’t, at all. Even if i had the breadboard outputs mixed up it should still change the segments on the LCD but nothing happens.

I should clarify that the LCD does work and so does the thumb wheel switch so I think it is a problem with the code.

I’ve attached a copy of my code, thanks for any help!

Edit: probably should also mention the LCD is anode so LOW = on

LCD_counter.ino (4.15 KB)

const int A = 1;
const int B = 2;            //assigning the 7 segment display outputs
const int C = 3;
const int D = 4;
const int E = 5;
const int F = 6;
const int G = 7;

const int pin1 = 13;        //Assigning the thumbwheel inputs
const int pin2 = 12;
const int pin3 = 11;
const int pin4 = 10;

void setup() {

  
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);               //Declaring the 7 segment display as outputs
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);

  pinMode(pin1, INPUT);
  pinMode(pin2, INPUT);              //Declaring the thumbwheel as inputs
  pinMode(pin3, INPUT);
  pinMode(pin4, INPUT);
  

}

void loop()
{
  if (digitalRead (pin1) == LOW,                    // Code to display 0
      digitalRead (pin2) == LOW,
      digitalRead (pin3) == LOW,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, HIGH);
   

  }
  else if (digitalRead (pin1) == HIGH,                  // Code to display 1
      digitalRead (pin2) == LOW,
      digitalRead (pin3) == LOW,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
     }
     
  else if (digitalRead (pin1) == LOW,            //Code to display 2
      digitalRead (pin2) == HIGH,
      digitalRead (pin3) == LOW,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, HIGH);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, HIGH);
    digitalWrite(G, LOW );
  }
  
  else if (digitalRead (pin1) == HIGH,            //Code to display 3
      digitalRead (pin2) == HIGH,
      digitalRead (pin3) == LOW,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, LOW );
}
  else if (digitalRead (pin1) == LOW,            //Code to display 4
      digitalRead (pin2) == LOW,
      digitalRead (pin3) == HIGH,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW );
}

else if (digitalRead (pin1) == HIGH,            //Code to display 5
      digitalRead (pin2) == LOW,
      digitalRead (pin3) == HIGH,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, HIGH);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW );
  }    
 else if (digitalRead (pin1) == LOW,            //Code to display 6
      digitalRead (pin2) == HIGH,
      digitalRead (pin3) == HIGH,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
  }    
 else if (digitalRead (pin1) == LOW,            //Code to display 7
      digitalRead (pin2) == HIGH,
      digitalRead (pin3) == HIGH,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
  }    
  else if (digitalRead (pin1) == LOW,            //Code to display 8
      digitalRead (pin2) == HIGH,
      digitalRead (pin3) == HIGH,
      digitalRead (pin4) == LOW)

  {
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
  }    
  else

  {
    digitalWrite(A, LOW);                //code to display 9
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
  }    
}
  else if (digitalRead (pin1) == LOW and         //Code to display 4
      digitalRead (pin2) == LOW and
      digitalRead (pin3) == HIGH and
      digitalRead (pin4) == LOW)
...

It is a bad practice to use single capital letters as identifiers.

const int F = 6;

The code is clumsy but may work if you use the and operator ( && ) when testing the inputs

UKHeliBob:
The code is clumsy but may work if you use the and operator ( && ) when testing the inputs

OP, "and" is a synonym for "&&". You can use either.

Thanks guys, I figured it would be something simple like that, I'll have to give it a shot tomorrow, I don't have the board with me.