15

I am new to programming and I thought a simple project to do would be to create an ammo counter. I have been troubleshooting this code for several hours now, and can not figure out why my code is riddled with errors. Below is my program. Please give it a glance and let me know what mistake I have made. I will post the error report beneath my program. I apologize for my bad programming in advance and hope that there is still hope for me with the proper tutelage. The program worked just fine when I ran a test using only one saved function, "twentyBullets()". After I added a 30 additional functions and created a chain of if-else-if conditions, the program began to report all sorts of errors.

 /* 
    7-SEGMENT DISPLAY HANDLING CODE!
    The below code handles the 7-segment display for the digital ammo counter.

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

 Above is the alphabet letter assignment for the different segments of
 the B07BMPPNQY display. Digital ammo counter project will use common pins, L3 and L4.
 */
  // Display pin declaration.
  // P_: Where P indicates the pin output for the segment of the display to be illuminated followed by a lower case letter
  // which indicates which specific led in the segment to illuminate.
  // ten: Where ten indicates the ten's place on the 7 segment display.
  // one: Where one indicates the one's place on the 7 segement display.

int Pa = 0;
int Pb = 1;
int Pc = 2;
int Pd = 3;
int Pe = 4;
int Pf = 5;
int Pg = 6;
int ten = 7;
int one = 8;
int ammo = 10;

void setup() {
  // put your setup code here, to run once:

pinMode(Pa, OUTPUT);
pinMode(Pb, OUTPUT);
pinMode(Pc, OUTPUT);
pinMode(Pd, OUTPUT);
pinMode(Pe, OUTPUT);
pinMode(Pf, OUTPUT);
pinMode(Pg, OUTPUT);
pinMode(ten, OUTPUT);
pinMode(one, OUTPUT);

}

void loop(){
  // put your main code here, to run repeatedly:
  if (ammo == 1) {
  oneBullet();
  }
  else if (ammo == 2) {
  twoBullets();
  }
  else if (ammo == 3) {
   threeBullets();
  }
  else if (ammo == 4) {
    fourBullets();
  }
  else if (ammo == 5) {
    fiveBullets();
  }
  else if (ammo == 6) {
    sixBullets();
  }
  else if (ammo == 7) {
    sevenBullets();
  }
  else if (ammo == 8) {
    eightBullets();
  }
  else if (ammo == 9) {
    nineBullets();
  }
  else if (ammo == 10) {
    tenBullets();
  }
  else if (ammo == 11) {
    elevenBullets();
  }
  else if (ammo == 12) {
    twelveBullets();
  }
  else if (ammo == 13) {
    thirteenBullets();
  }
  else if (ammo == 14) {
    fourteenBullets();
  }
  else if (ammo == 15) {
    fifteenBullets();
  }
  else if (ammo == 16) {
    sixteenBullets();
  }
  else if (ammo == 17) {
    seventeenBullets();
  }
  else if (ammo == 18) {
    eighteenBullets();
  }
  else if (ammo == 19) {
    nineteenBullets();
  }
  else if (ammo == 20) {
   twentyBullets();
  }
  else if (ammo == 21) {
   twentyoneBullets();
  }
  else if (ammo == 22) {
    twentytwoBullets();
  }
  else if (ammo == 23) {
    twentythreeBullets();
  }
  else if (ammo == 24) {
    twentyfourBullets();
  }
  else if (ammo == 25) {
    twentyfiveBullets();
  }
  else if (ammo == 26) {
    twentysixBullets();
  }
  else if (ammo == 27) {
   twentysevenBullets();
  }
  else if (ammo == 28) {
   twentyeightBullets();
  }
  else if (ammo == 29) {
   twentynineBullets();
  }
  else if (ammo == 30){
   thirtyBullets();
  }
  else {
    zeroBullets();
  }
}
void zeroBullets()
           //0
{ digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

        //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void oneBullet()
          //1
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}

void twoBullets()
          //2
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void threeBullets()
          //6
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fourBullets()
          //4
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fiveBullets()
          //5
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void sixBullets()
          //6
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void sevenBullets()
          //7
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void eightBullets()
          //8
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void nineBullets()
              //9
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void tenBullets()
              //0
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void elevenBullets()
              //1
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void twelveBullets()
             //2
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void thirteenBullets()
          //3
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fourteenBullets()
          //4
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fifteenBullets()
          //5
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void sixteenBullets()
          //6
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void seventeenBullets()
          //7
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void eighteenBullets()
          //8
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void nineteenBullets()
          //9
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void twentyBullets()
        //0
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyoneBullets()
        //1
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentytwoBullets()
        //2
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentythreeBullets()
        //3
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyfourBullets()
        //4
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyfiveBullets()
        //5
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentysixBullets()
        //6
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentysevenBullets()
        //7
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyeightBullets()
        //8
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}  
void twentynineBullets()
      //9
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}

void thirtyBullets()
        //0
  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //3
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}

THE ERROR REPORT:

Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

Digital_Ammo_Counter.ino: In function 'void loop()':

sketch_Digital_Ammo_Counter:138:4: error: 'thirtyBullets' was not declared in this scope

    thirtyBullets();

    ^~~~~~~~~~~~~

sketch_Digital_Ammo_Counter.ino:138:4: note: suggested alternative: 'twentyBullets'

    thirtyBullets();

    ^~~~~~~~~~~~~

    twentyBullets

sketch_Digital_Ammo_Counter.ino: At global scope:

sketch_Digital_Ammo_Counter:898:3: error: expected initializer before 'digitalWrite'

   digitalWrite(one, LOW);

   ^~~~~~~~~~~~

sketch_Digital_Ammo_Counter:899:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(ten, HIGH);

               ^

sketch_Digital_Ammo_Counter:900:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pa, LOW);

               ^

sketch_Digital_Ammo_Counter:901:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pb, LOW);

               ^

sketch_Digital_Ammo_Counter:902:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pc, LOW);

               ^

sketch_Digital_Ammo_Counter:903:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pd, LOW);

               ^

sketch_Digital_Ammo_Counter:904:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pe, LOW);

               ^

sketch_Digital_Ammo_Counter:905:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pf, LOW);

               ^

sketch_Digital_Ammo_Counter:906:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pg, HIGH);

               ^

sketch_Digital_Ammo_Counter:907:8: error: expected constructor, destructor, or type conversion before '(' token

   delay(10);

        ^

sketch_Digital_Ammo_Counter:910:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(one, HIGH);

               ^

sketch_Digital_Ammo_Counter:911:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(ten, LOW);

               ^

sketch_Digital_Ammo_Counter:912:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pa, LOW);

               ^

sketch_Digital_Ammo_Counter:913:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pb, LOW);

               ^

sketch_Digital_Ammo_Counter:914:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pc, LOW);

               ^

sketch_Digital_Ammo_Counter:915:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pd, LOW);

               ^

sketch_Digital_Ammo_Counter:916:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pe, HIGH);

               ^

sketch_Digital_Ammo_Counter:917:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pf, HIGH);

               ^

sketch_Digital_Ammo_Counter:918:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pg, LOW);

               ^

sketch_Digital_Ammo_Counter:919:8: error: expected constructor, destructor, or type conversion before '(' token

   delay(10);

        ^

sketch_Digital_Ammo_Counter:920:1: error: expected declaration before '}' token

 }

 ^

exit status 1
'thirtyBullets' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
11
  • 3
    The way this got formatted absolutely screwed up the copy/paste of my program and my error report. If you would like to help me and need to see something that looks more like my actual program and/or error report, I can arrange to email either document. – pvGuy Nov 29 '19 at 7:20
  • 4
    upvote for checking the format of your posted code ... so many people just don't serm to care if the code is readable .... put three backticks ``` in a line above your code and three backticks in a line after your code – jsotola Nov 29 '19 at 7:40
  • 3
    I have formatted the code for you. +1 for caring – chrisl Nov 29 '19 at 7:47
  • 3
    Don't feel bad about the missing curly brace. That causes most compilers to "lose their minds," generating a whole bunch of very confusing error messages, and can be very hard to track down. I've been programming in C and C-like languages for >30 years, and this exact problem still bites me from time to time. – Duncan C Nov 29 '19 at 14:25
  • 6
    Here's some advice I give all of my students: Compilers compile syntactically correct programs, and catch & report basic errors, but they're useless at allowing for the errors they've already seen. One simple error, such as your missing brace, can often cause a whole cascade of error messages that seem unrelated to the original error. Fix the first error (or 2, if you notice that the 2d one is real) and recompile. You'll find that one mistake with "tons of error messages" pretty quickly and save a lot of time over trying to analyze the following, correct, pieces of code. – JRobert Nov 29 '19 at 17:34
41

The error cascade is caused by the missing opening curly bracket { at the start of the thirtyBullets() function. This causes the function name to be not declared and also the following function calls to digitalWrite() to fail. Putting in this missing opening curly bracket should fix all the errors (though I cannot test it since I don't have a compiler at hand currently).

Besides that, your code can be made way shorter with a trick. Currently you use one function for every number, where you write the corresponding digital pins. So the situation is, that you always need to write to the same pins, just different values depending on a simple unsigned integer number. So I suggest, that you define the pin patterns for the digits in a 2 dimensional array. Then you can use only 1 function to output any of them. I will give you an example:

uint8_t led_pattern[10][7]= {
    {0, 0, 0, 0, 0, 0, 1}, // pattern for the digit 0
    {1, 0, 0, 1, 1, 1, 1}, // pattern for the digit 1
    {0, 0, 1, 0, 0, 1, 0}, // pattern for the digit 2
    ...
    {0, 0, 0, 0, 1, 0, 0}}; // pattern for the digit 9

void display_digit(uint8_t position, uint8_t digit){
    digitalWrite(one, position); // Writes low (aka zero) to pin one, when position is zero, else high
    digitalWrite(ten, !position); // Writes low to pin ten, when position is greater than zero, else high

    for(uint8_t i=0; i<7; i++){
        digitalWrite(i, led_pattern[digit][i]);
    }
    delay(10);
}

void display_number(uint8_t number){
    display_digit(0, number % 10);
    display_digit(1, number / 10);
}

void loop(){
    display_number(ammo);
}

So, what is happening here?

First we define the LED patterns in a 2 dimensional array. It's first index is the digit, that we want to display; it's second index is the number of the LED to light. The value then is the state of the corresponding LED. I wrote 1 and 0, because it is short. You could also write HIGH and LOW (since these are also only defines for 1 and 0). So the pattern {1, 0, 0, 1, 1, 1, 1} means, that only the segments b and c output low, thus are turned on.

Then we define a function to display one digit. It takes the position of the digit and the actual digit (0 to 9) as parameters. We write the two outputs for our position directly with the variable. This is a very short way to do it and it doesn't work, when you have more than 2 digits. If you want to extend your counter one day, you can replace these 2 lines by a different construct (for example a switch case statement). Then we do a for loop from 0 to 6, so that we go through all the digits. In your case you use the pin numbers 0 to 6, so we can directly use i as pin number. (If you want to use other pins, you could save those pins in an array and reference the values in the array with i). In every iteration of the for loop, we write the value for the corresponding digit and LED to the corresponding output pin. After that, we only delay a short time and leave the function.

To make it easier, I also defined the function display_number(), which will display the complete number, by displaying the it's digits successively on the corresponding positions. If you are a beginnner, you might not recognize, what calculations I made there. The modulo operator % returns the rest of an integer division. So if I take 23 % 10 this would return 3 (integer division 23 / 10 is 2 and the rest is 3). This gives us the first (least significant) digit. We can then get the second digit by simply doing an integer division with 10, as it will cut the part after the decimal point. If you want to display numbers greater than 99 one day, you have to change both functions to accomodate for that.

Note, that I used uint8_t as type everywhere. This is just the smallest unsigned number type (8 bit wide). I used the smallest, since you don't need greater numbers here and it saves a bit of memory. When you want to extend your display to show values greater than 255, you need to change the type of the number parameter in the display_number() function to a greater type, for example unsigned int (which is 16 bits wide).

Also note, that I have not tested this code, since I don't have a compiler or Arduino at hand currently.


So now, you can display a number on your digit with just one function call and you don't need nearly 1000 lines of code for it.

When extending your code to do more things, than displaying numbers, you can easily get to the point, where using delay() is a bad thing, since the Arduino cannot do anything else during that time. Then you need to rewrite your code to avoid delay() and use the millis() function instead to make it unblocking. There are tons of tutorials out there for this and I just wanted to mention it.

4
  • 3
    Good lord! I am kicking myself in the butt hard for forgetting something so humble as a "{"! It has caused me great suffering. I bow down before your Arduino knowledge and thank you for not only finding the error in my code, but also for showing me a much better way to go about the entire process! You have my very most sincere thanks! Wow, I will definitely dig deeper into tutorials on Arduino! Hopefully I will be as knowledgeable as you on the subject at some point! – pvGuy Nov 29 '19 at 8:44
  • 12
    Thank you, but that's enough of praise. We all started at that point. It's all about the learning experience. You can accept my answer as correct, if you think, it is correct. And maybe you want to come back some day and also answer question yourself. We are always happy to find new contributors :D – chrisl Nov 29 '19 at 8:52
  • 7
    Well done, providing both the narrowly focused answer AND guidance on using arrays to solve the problem more elegantly. (voted.) I guess we're not gonna try to walk a beginner through decoding binary using bit masking & shifting... – Duncan C Nov 29 '19 at 13:33
  • 1
    since I don't have a compiler at hand currently) I suggest godbolt.org, Matt Godbolt's compiler explorer. It has GCC, Clang, MSVC and ICC installed, including GCC for ARM and for AVR. With color highlighting to match source lines to asm output lines. (And languages including C, C++, Rust, Go, Haskell, ...) Your code compiled as C for ARM cortex M3: godbolt.org/z/-K_muB – Peter Cordes Nov 30 '19 at 11:00
8

You've found the bug, but how could you have found it easier?

The most important step mentally is to accept that you did something wrong. We don't know yet what, but it is exceedingly unlikely that the compiler complains about correct code. So the question is: What did you do wrong?

The compiler complained about a function "thirtyBullets". It didn't complain about "twentynineBullets". It doesn't realise that there is a function "thirtyBullets". The first thing is to check the spelling. If you named the function "thirrtyBullets" by mistake, that would explain things. But the name is right.

Then you see that the compiler complains about the line immediately after the start of the function. Hard to figure out what the compiler is complaining about, so something you did just before confused it. So now you check the line "void thirtyBullets()", that's Ok, the next line "digitalWrite(one, LOW);" looks Ok but something MUST be wrong here, and that's where you hopefully figure out the missing "{".

0
1

Just to add to the idea of using an array—since C does not care about whitespace you can quite easily format your data like this:

uint8_t led_pattern[10][7]= {
      {0,  // pattern for the digit 0
     0,  0,
       0,
     0,  0,
       0},

      {0, // pattern for the digit 1
     0,  1,
       0,
     0,  1,
       0},


      {1, // pattern for the digit 2
     0,  1,
       1,
     1,  0,
       1},
      ...
};

This is an example of the "good habit" of making your code about your intent rather than about instructing the machine. You can spend 50% more time making your code clear, or spend 500% more time debugging it. As the saying goes,

There are two ways to develop software: Make it so simple that there are obviously no bugs, or so complex that there are no obvious bugs.

Note: The above code will give you your digitalOut values in a different order to your pins (so chrisl's for loop won't work.) You can just manually do 7 digitalWrites to the correct pins when displaying the digit.

digitalWrite( <pin number> , led_pattern[digit][ <led position> ]);
0

Your code actually isn't bad. There aren't very many good ways of doing this sort of pin mapping, and the few that are have their own downsides as well. The main issue was the missing bracket, which I found by checking the drawThirty function since it was mentioned specifically and had cascading errors implying a missed semicolon or bracket.

One further tweak is that your code will only work on Arduino (so you're fine, but a different IDE may get mad at you). C does not search the whole file for function names, so if you declare/define the function after you use it, it will error out. Arduino uses a special pre-parser to fix this for you.

The proper way is to forward-declare the function as follows:

int returnAPieceOfData(byte x, char c, int i);//Now C knows it exists somewhere and won't error.

void foo(){

//somewhere in here you need returnAPieceOfData
}

int returnAPieceOfData(byte x, char c, int i){
//You now define the function after it's used, but have no errors!

}

This usually results in a C file where all the functions are declared at the top, and then the function definitions below can use them in any order without problems. It also makes it easier to tell if the file has a function, and if you add them in the same order, where it is.


I will mention a potentially-useful method of alternately implementing the array lookup table for writing the pins. The above are very good suggestions, especially the shaped whitespace, but that approach will use a lot of extra memory because it uses full bytes per pixel.

If you are willing to accept a format that is somewhat harder to visualize, you could encode the entire space into a single byte, which I'll show below. You can also put the pin numbers into an array so that you can use a FOR loop.

Essentially, you have two options when writing this sort of system. You can go for code complexity, which is what your example did, or you can go for memory/data complexity, which I'm showing here. The downsides to THIS technique are that the data is somewhat arcane and hard to modify (since it's encoded and there's kinda a lot of it), and that it uses extra memory to hold that data.

void drawAllSegments(byte ammo_ct){
  byte hi=ammo_ct/10;
  byte lo=ammo_ct%10;
  drawLowSegments(lo);
  drawHighSegments(hi);
}


byte lpinNums[]={apin,bpin,cpin,dpin,epin,fpin,gpin};//pins for 0s display
byte hpinNums[]={apin,bpin,cpin,dpin,epin,fpin,gpin};//pins for 10s display
byte numbers[]={0b00111111,0b01111001,...};
//Format the "numbers" as 0bXGFEDCBA, where X is a don't-care
//(its value is never used and can be either 0 or 1)
//My example may be wrong. I think it's negative logic, but could also have made an error on top of that.

void drawLowSegments(byte ammo_ct){
  digitalWrite(one, HIGH);//set up the display select
  digitalWrite(ten, LOW);
  for (byte i=0;i<7;i++){//then draw!
    byte state=(numbers[ammo_ct]>>i)&0x01;//decompress the state of that segment
    digitalWrite(lpinNums[i],state);
  }
}

void drawHighSegments(byte ammo_ct){
  digitalWrite(one, HIGH);//set up the display select
  digitalWrite(ten, LOW);
  for (byte i=0;i<7;i++){//then draw!
    byte state=(numbers[ammo_ct]>>i)&0x01;//decompress the state of that segment
    digitalWrite(hpinNums[i],state);
  }
}

The advantages of this approach is that the code is just as compact as the array system, but that it uses 1/8 the RAM for that array. I don't imagine you are doing something that uses a whole lot of RAM, but it's still a good idea to minimize it where possible. In this case it also is much further expandable, since you can fit more numbers in before you run out of RAM.

You can also switch to PROGMEM, but reading that is a bit weird in some ways and it's easy to forget to read it in the first place (which results in reads of random RAM). In this case it should be small enough that further such optimization isn't required.

One last note is that, if you ever do something for which a byte is too small, you can use larger numbers up to the uint32_t, which is 32 bits of useful pixels, or potentially the uint64_t, which is 64 bits but may not be supported on the Arduino (I've never tried the latter).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.