Segment display increment/decrement code

So I've been working on a little project to make my segment display start at a certain number and then increment or decrement with a simple button press.

I am somewhat new to code so if the answer is obvious, please forgive me, but after some frustrating days on google trying to figure out what I did wrong, I don't know why my code doesn't work.

(the code is not done yet, i still have to write the code to show the rest of the numbers to 99, if there is a simpler way to do this please tell me)

/*Life counter using dual 14 segment display.
pins alligned from left to right, bottom then top
using pins 1-13. Switch is using pin 2 to decrement, 8 to increment.
default starting number is 25.*/

// Common Anode digit 1 left pin 4
// Common Anode digit 2 left pin 6
// Common Anode digit 1 right pin 10
// Common Anode digit 2 left pin 13

//     D E  ca3 F    G  ca4
//     | |    | |    |   |      -> pins and segments they control
//   ----G----    ----G----
//   | \ E / |    | \ E / |
//  F| D\|/D |F  F| D\|/D |F
//   |-A- -A-|    |-A- -A-|
//  C| B/E\B |C  C| B/E\B |C
//   | / | \ |    | / | \ |
//   ----G----dp1 ----G----dp2
//     |    | | | |     | |     -> pins and segments they control
//     A    B C ^ dp1   ^ dp2
//            (ca1)   (ca2)




int led1Pin = 1;
//int led2Pin = 2; removed for room for switch inputs
int led3Pin = 3;
int ca1Pin = 4;
int led5Pin = 5;
int ca2Pin = 6;
//int led7Pin = 7; removed for room for switch inputs
int led9Pin = 9;
int ca3Pin = 10;
int led11Pin = 11;
int led12Pin = 12;
int ca4Pin = 13;
int debuggled7Pin = 7;

int minusswitchPin = 2;
int minusState = 0;

int plusswitchPin = 8;
int plusState = 0;

int lifetotal = 3;

void setup() {
  pinMode(led1Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(ca1Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);
  pinMode(ca2Pin, OUTPUT);
  pinMode(led9Pin, OUTPUT);
  pinMode(ca3Pin, OUTPUT);
  pinMode(led11Pin, OUTPUT);
  pinMode(led12Pin, OUTPUT);
  pinMode(ca4Pin, OUTPUT);
  
  pinMode(minusswitchPin, INPUT);
  pinMode(plusswitchPin, INPUT);
  
  pinMode(debuggled7Pin, OUTPUT);
}



void changeLifetotal(){
    //incrimenting switch
  plusState = digitalRead(plusswitchPin);
  if (plusState == HIGH){
    digitalWrite(debuggled7Pin, HIGH);
    lifetotal = lifetotal + 1;
  }
  else{
    digitalWrite(debuggled7Pin, LOW);
    lifetotal = lifetotal;
  }
  
  //decrimenting switch
  minusState = digitalRead(minusswitchPin);
  if(minusState == HIGH){
    digitalWrite(debuggled7Pin, HIGH);
    lifetotal = lifetotal - 1;
  }
  else{
    digitalWrite(debuggled7Pin, LOW);
    lifetotal == lifetotal;
  }
}





void loop() {  
  //in case of numbers < 0 or > 100
  if(lifetotal > 99){
    lifetotal = 0;
  }
  if(lifetotal < 0){
    lifetotal = 99;
  }

  //lifetotals displayed  
  while(lifetotal == 0){
    digitalWrite(ca1Pin, HIGH);//function for 0
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    digitalWrite(led11Pin, HIGH);
    digitalWrite(led12Pin, HIGH);
  }
  while(lifetotal == 1){//function for 1
    digitalWrite(ca1Pin, HIGH);
    digitalWrite(ca2Pin, HIGH);
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    digitalWrite(led11Pin, HIGH);
  }
  while(lifetotal == 2){//function for 2
    digitalWrite(ca1Pin, HIGH);
    digitalWrite(ca2Pin, HIGH);
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led11Pin, HIGH);
    digitalWrite(led12Pin, HIGH);
    delay(1);    
    digitalWrite(ca2Pin, LOW);
    digitalWrite(ca1Pin, HIGH);
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(ca4Pin, HIGH);
    digitalWrite(led11Pin, LOW);
    digitalWrite(led3Pin, HIGH);
    delay(1);
    digitalWrite(led3Pin, LOW);
    digitalWrite(ca4Pin, LOW);
  }
  while(lifetotal == 3){//function for 3
    digitalWrite(ca1Pin, HIGH);
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(ca4Pin, HIGH);
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led12Pin, HIGH);
    delay(1);
    digitalWrite(ca4Pin, LOW);
    digitalWrite(ca2Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    digitalWrite(led11Pin, HIGH);
    delay(1);
    digitalWrite(ca2Pin, LOW);
    digitalWrite(led3Pin, LOW);
    digitalWrite(led11Pin, LOW);
  }
  while(lifetotal == 4){//function for 4
    digitalWrite(ca1Pin, HIGH);
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(ca4Pin, HIGH);
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led11Pin, HIGH);
    delay(1);
    digitalWrite(ca4Pin, LOW);
    digitalWrite(ca2Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    delay(1);
    digitalWrite(ca2Pin, LOW);
    digitalWrite(led3Pin, LOW);
  }
  while(lifetotal == 5){//function for 5
    digitalWrite(ca1Pin, HIGH);
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(ca4Pin, HIGH);
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led11Pin, HIGH);
    digitalWrite(led12Pin, HIGH);
    delay(1);
    digitalWrite(ca4Pin, LOW);
    digitalWrite(ca2Pin, HIGH);
    digitalWrite(led11Pin, LOW);
    digitalWrite(led3Pin, HIGH);
    delay(1);
    digitalWrite(ca2Pin, LOW);
    digitalWrite(led3Pin, LOW);
  }
}

Delta_G:

while(lifetotal == 0){

digitalWrite(ca1Pin, HIGH);//function for 0
    digitalWrite(ca3Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    digitalWrite(led11Pin, HIGH);
    digitalWrite(led12Pin, HIGH);
  }




Maybe this should be an if statement and not a while. As a while, it will keep doing this until lifetotal doesn't equal 0 anymore. Since there's no code inside this block that could allow lifetotal to ever change, you'll be stuck in this block forever.

the purpose of the switches are to change the lifetotal, are you saying i should move those into the "void loop" block?

and i can see how an "if" statement would work here though.

alright so changing all the "while" statements to "if" statements fixed everything, i guess i need to make sure i understand the "while" loop a bit better.

thank you for everything!

Simplify? I'd begin by rethinking your segment naming convention. It's overly elaborate and confusing. Follow the 7 segment principle and just name them consecutively, ABCDEFG.... but you obviously need a few more. All this left F and right F, anode and cathode and up and down is just too tricky to deal with.

It appears that there are two common anodes per digit. Yes, you will have to deal with that. But don't pollute your naming with that. Create a table (array) that contains the correct anode and cathode for each segment. Then reference that table when you need to reference a segment.

The payoff for this effort comes when you try to do what you said you wanted to do, namely sending 2 digit numbers to the display.

aarg:
Simplify? I'd begin by rethinking your segment naming convention. It's overly elaborate and confusing. Follow the 7 segment principle and just name them consecutively, ABCDEFG.... but you obviously need a few more. All this left F and right F, anode and cathode and up and down is just too tricky to deal with.

It appears that there are two common anodes per digit. Yes, you will have to deal with that. But don't pollute your naming with that. Create a table (array) that contains the correct anode and cathode for each segment. Then reference that table when you need to reference a segment.

The payoff for this effort comes when you try to do what you said you wanted to do, namely sending 2 digit numbers to the display.

i'm quite confused? so name each digit like:

---A---
| |
F| |B
| |
---G---
| |
E| |C
| |
---D---

?

the way my display would work would be more like:

---A---
| |
B| |B
| |
-D- -D-
| |
C| |C
| |
---A---

im pretty sure you know what you're talking about and i'm just misunderstanding...

What you have is an alphanumeric display, such as

you should use the segment naming they use to be standard with everyone else.

Dual displays usually have the segments in parallel between the devices, with a common anode (or cathode) for each digit, and sometimes two common anodes (or cathodes) per digit for better current flow.

You need to multiplex between them. Drive the segment, drive a transistor to control the common pin.
Leave it on a few seconds. Turn off, set up segments again, drive the other common pin.

I'd create a fontArray
int fontArray[] = {
0b0010001000111111, // 0 // 0-DP-p-n-m-l-k-j-h-g-f-e-d-c-b-a
etc
};

then send those bits out to the relevant pins.
byte pinsArray[] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,}; // a-b-c-d-e-f-g-h-j-k-l-m-n-p-DP

I'd do it using direct port manipulation, send lower 6 bits of fontArray[digitToDisplay] to portD 2-7, the next 6 bits to portB 0-5, and the last 3 to portC 0-2, leaving D17-D18 for transistor control.
D19 for whatever, and D0/D1 for serial.

I'd add two shift registers. Send lowByte (fontArray[leftDigit]) and highByte(fontArray[leftDigit]) to the shift registers, enable the common digit pin, a few mS later send the data for the rightDigit and enable its common pin.
Persistence of vision will trick your eye into seeing both digits on.

hmmm, this is all above me to be honest, but nothing a few hours on google and youtube cant fix. i dont have any transistors however... so i'll have to get some.