text:
My code seems to be a train wreck
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.

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.

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

you can also select all of the code and click the {} button

I have formatted the code for you. +1 for caring

Thank you all very much! I'll keep the formatting fixes in mind from now on and thank you, kind person, for taking the liberty to format my code for me.

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.

Haha, thanks! Yeah, I figure we all fall prey to simple oversight from time-to-time. With more experience, I am sure I'll be able to pick up on mistakes like this more quickly. I'm just glad that the community is so good! I have to say, I wasn't expecting all the support I have been getting! It's fantastic and I hope that I too will be of some assistance to the next generation of beginner electronics enthusiasts.

It helps that you provided a complete description of your problem. Lots of beginning posters post post vague "I tried ... but it doesn't work" questions, and then it takes an exhausting game of 20 questions to figure out what "it doesn't work" actually means

While I'm aware a code review isn't what is being asked for, I would strongly urge you to reconsider your approach here. Copy/pasting code should be an immediate red flag to suggest that you need to approach this more cleverly. A basic suggestion that you can tackle as a beginner would be a method that prints a given digit (and then your number logic becomes digit + digit logic). If you work with the bloated and increased code that you have now, any change or bug is going to take up much more time than it should. What happens if you can have up to 99 bullets tomorrow?

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.

The best advice that I can give is, once the code compiles (and I personally do not tolerate any warnings, ever), is to learn how to use the debugger. It is your best friend in all the world. Set "breakpoints", run your code and it will stop when it encounters a breakpoints, at which point you can examine the call stack, read and even change the value of variables, and more. It's by  far the best way to et insight into what your code is doing.

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.

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!

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

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...

since I don't have a compiler at hand currently) I suggest https://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: https://godbolt.org/z/-K_muB

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 "{".

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> ]);

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).


text:
Arduino Uno - Can' get LCD Display work crrectly
I make an automatic light that's triggered from a Visitor Counter. I use an LCD to show the actual counter state. The LCD does not anly show the actual count but also the numbers before. For Example:
If the counter is actual 2, it blinks between 1 and 2.
This behavior does not occur in the original project where the correct number is shown.
Please, can I know why, and how to fix it? Thank you!

This is the code:
//Visitors Counter and Automatic Room Light
//Viral Science  www.youtube.com/c/viralscience

#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);

#define in 14
#define out 19
#define relay 2

int count=0;

void IN()
{
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}

void OUT()
{
  count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}

void setup()
{
  lcd.begin(16,2);
  lcd.print("Visitor Counter");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay, OUTPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);
}

void loop()
{

  if(digitalRead(in))
  IN();
  if(digitalRead(out))
  OUT();

  if(count<=0)
  {
    lcd.clear();
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Is Off");
    delay(200);
  }

  else
    digitalWrite(relay, HIGH);

}

What is the actual program? What is the difference between the actual and your program? What is the code anyway?  And do you mean by blinking it shows alternately 1 and 2?  To fix it, probably you have to change the code, or the circuit, but high likely the code. But this 'answer' is as vague as your question I'm afraid.

Yes sir @Michel Keijzers it keep blinking and shows alternately 1 and 2 . I will try compile a new coding and see what happen . Thank you sir !

Please add the code ( that is not working ) to the question. You asked why the code does not work and how to fix it. To answer we must know it. Simply, writing new code seems not to be the best strategy. Perhaps it works, but then you don't know why the first code did not. Or it does not work; what will you do then? Please do not report that your second code does also nor work, without showing it here. We can not guess what you have programmed so far.

I suggested to change the text and the title of the question as I edited it. If I understood it correctly, please accept die update. It hopefully make the question more understandable.  (Although my English is bad.) I have not access to your code, so it remains to you to add it to make the question a lot more understandable.

No, please do not add the code to a comment. Just edit your question and add it at the end of your question. Then mark the code completely and press the {} button of the online editor. You'll get well formatted code. You have not enough space in a comment. And the code should be part of the question.

The code you added is the original code from https://www.viralsciencecreativity.com/post/arduino-visitors-counter-automatic-light from which you said it would work. If you want us to find the error you made, we need to see your code, that might be wrong. So please add the code you have changed, and that does NOT work. And the code from the video only works if you have separate doors. One to go in and one to go out. If you pass the two sensors in one door you get an in and an out event. If I didn't missed anything. ;-)

If you want to say that it works in the video but not for you, than it is perhaps because the author did a trick. He uses a plank to disable both sensors at the same time. Then he moves the plank to only activate one sensor. It depends on which sensor is released , whether the counter was increased or decreased. He simulates the two doors I mentioned. And he had to doo this within one second. Or the counter remains increasing or decreasing.

For what ever reason IN() and OUT() get called at the same time. I see no obvious mistakes in the code, do I assume it has something to do with your setup. But your approach won't work anyway, because IN(( and OUT() will get called as lang as a person enters/leaves. What you need is to detect signal edges rather than levels (or does your sensor detect s.o.passing by and generate such a signal?)

So what i can do to eliminated the blinking effect on the lcd based on the infrared sensors detection?

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
automated parking system (sir sensor+ stepper motor)
my project about automated system I am using stepper motor to open and close the gate
I want my code be like when the gate opened it stays 5 seconds
then check the sensor, if there is a motion the gate should not close and stay open, when there is no motion the gate should close
if the gate is closing and there is a motion, motion should interrupt closing the gate and reopening the gate
I am using Arduino uno
the code is :
#include <RH_ASK.h>//include radioHead ASK library
#include <SPI.h> // include dependant SPI libray
#include <Stepper.h> // Include the Arduino Stepper.h library:
// Define number of steps per rotation:

RH_ASK rf_driver; // create ASK object
int ledon = 13;
int ledoff = 5;
int sensor = 3;

const int stepsPerRevolution = 2048;// Define number of steps per rotation:

// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {

  rf_driver.init(); //initialize ASK object

  // Begin Serial communication at a baud rate of 9600:
  Serial.begin(9600);

  // Set the speed to 5 rpm:
  myStepper.setSpeed(5);
  pinMode(ledon, OUTPUT);
  pinMode(ledoff, OUTPUT);

}

void loop() {

  //set buffer to size of expected message
  //uint8_t buf[8];
  // uint8_t buflen =sizeof(buf);

  //check if recevied packet is correct size
  //  if (rf_driver.recv(buf,&buflen))
  //{
  // int i;
  // message received with valid checksum
  // Serial.print("id: ");
  // Serial.println((char*)buf);
  // String userid =(char*)buf;
  // Serial.println(userid);

  // }

  //delay(5000);

  // uint8_t buf2[8];
  // uint8_t buflen2 = sizeof(buf2);

  // if (rf_driver.recv(buf,&buflen))

  // {

  //  int i;
  // message received with valid checksum
  // Serial.print("password: ");
  // Serial.println((char*)buf);
  // String password = (char*)buf;
  //  Serial.println(password);

  // }
  // delay(5000);

  String pass = "1234";
  String id = "A00036757";

  if (pass == "1234" ) {
    Serial.print("car exists");
    digitalWrite(ledon, HIGH);
    delay(300);
    myStepper.step(stepsPerRevolution / 3); //clockwise -OPEN GATE
    delay(10000);

    //if(digitalRead(sensor) == HIGH){
    delay(500);
  }

  if (digitalRead(sensor) == LOW) {

    digitalWrite(ledon, LOW);
    delay(300);

    digitalWrite(ledoff, HIGH);
    delay(300);
    myStepper.step(-stepsPerRevolution / 3); // CLOSE AFTER 5s COUNTERCLOCKWISE -  close gate
    digitalWrite(ledoff, LOW);
  }
  else {
    Serial.print("NO CAR");
  }

When you use delay(), your code stops and dont check anything at all until the delay is over, if you want to check for sensors during a timer, you have to use millis()
There is a lot of documentation and tutorials you can find to replace delay with millis when you know what you are searching for

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Arduino ds3231to TM1638 problems,alarm clock project
Good morning,
I am coding an alarm clock on arduino by using a DS3231 and a TM1638.
The code works and the time updates in the serial monitor,although the time doesn't update on the tm1638.
I'll attach the code here:
#include <DS3231.h>
#include <TM1638.h>
#include <Streaming.h>
#include <SPI.h>
#include <Wire.h>
#include <InvertedTM1638.h>
#include <TM1638.h>
#include <TM1638QYF.h>
#include <TM1640.h>
#include <TM16XX.h>
#include <TM16XXFonts.h>
byte buttons;
#define TM1638_STB D5
#define TM1638_CLK D6
#define TM1638_DIO D7

TM1638 module(TM1638_DIO, TM1638_CLK, TM1638_STB);
// DS3231 uses I2C - device ID 0x68
// on Wemos mini pins SDA -> D1 and SCL -> D2
DS3231 rtc;
int hours;
int minutes;
int seconds;
bool h12;
bool PM;
int data;
RifTime t;
char buffer[24];

void setup()
{
  // set up the 7-segment display
  module.clearDisplay();
  module.setupDisplay(true, 2);
  Wire.begin();
  Serial.begin(115200);

  Serial.println(F("\nDS3231 Hi Precision Real Time Clock"));

  // Fill these variables with the date and time.
  int seconds, minutes, hours, dayofweek, dayofmonth, month, year;

  // Example for april 15, 2013, 10:08, monday is 2nd day of Week.
  // Set your own time and date in these variables.
  // dayofweek = 4; // Day of week, any day can be first, counts 1...7
  hours = 14;
  minutes = 30;
  seconds = 0;
  year = 2019;
  month = 8; // month 1...12
  dayofmonth = 28; // Day of month, 1...31

  data=( hours * 10000 + minutes * 100 + seconds * 1 );

  rtc.setClock(year,month,dayofmonth,hours,minutes,seconds);
}

void loop()
{
  rtc.getTime(t);
  Serial << rtc.toString(buffer) << endl;

  delay(1000); // do nothing

  module.setDisplayToDecNumber(data,4,false);

  if(seconds==60)
  {
    seconds=00;
    minutes++;
  }
  if(minutes==60)
  {
    minutes=0;
    hours++;
  }

  if(hours==24)
  {
    data=00000000;
  }

  if((data)==143000)
  {
    module.setLEDs(0x0001);
  }
  else
  {
    module.setLEDs(0x0000);
  }

}

You set the variable data only in the setup function.
You also do not print out data to Serial but the output of rtc.toString(buffer).
If data is not updated in the loop method, the display constantly shows the time you initially set in the setup method.


text:
How to toggle LED and motor on button press?
we want to have a LED turn on with the press of a button, and become brigther and brighter as times go by (whithin  a defined time frame), and when it reaches maximum brightness to turn off for a couple of seconds and then start again. in addition to that, we are trying to add a motor that will start spinning 720 degrees when the button has been pressed.
Our main problem is the fact that when we let go of the button the led turns off. How do we set the button so that when it is pressed once it turns everything on, and the led runs in a loop, but the motor doesn't; and when we press it again the whole led turns off completely and the motor runs 720 degrees in the opposite spinning direction than the previous.
Here is what we have managed so far (we didn't get to introduce the motor yet as we got stuck along the way):
const int switchPin = 11;
const int motorPin = 6;
int led = 9;
int switchState = LOW;
int previous = LOW;
int i = 0;
int fadeAmount = 5;

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(motorPin, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop()
{
  int switchState = digitalRead(switchPin);

  for (int i = 0; i <= 255; i++)
  {
    analogWrite(led, i);
  }

  if (switchState == HIGH && previous == LOW)
  {
    if (i == 0)
    {
      digitalWrite (led, HIGH);
      i = i + fadeAmount;
      delay(1000);
    }

    analogWrite(led, i);

    for (int i = 255; i <= 255; i--)
    {
      digitalWrite (led, LOW);
      i = 0;
    }
  }
  else
  {
    //toggle off
    digitalWrite(led, LOW);
    i = 0;
  }
}

PS. WE are beginers. Thanks for the help and understanding!

you are getting distracted by the fading lights and by the motor .... the motor action and the fading lights action are completely separate from the button press action .... the motor and light could be triggered by a timer, by voltage level or by a number of other events ....... the lights should be controlled by a boolean variable ... name it lights_on for example ... the button should set the value of lights_on variable .... the value should be set only by the switch at the transition from button not-pressed state to button pressed state, not by the "pressed` state alone

start by writing button code that controls a single led ... button sets a variable .... LED responds to variable

Here is a program that should fade the LED as you specified. Initially the LED is off. If you press the button the LED starts fading within the time frame to its maximum. Then it switches to zero waits a couple of seconds and starts fading from new. If you press the button a second time the LED stops fading and is set to darkness. ;-) This happens emediately, but of cause, you can only see it if the LED is in the fading phase.
I used interrupts in order to have a well defined state transition I can work with.
Aquiring the button pin in the loop, would be more complex to handle. That would require a state variable and some state transition rules. And I was too lazy to work that out. If interupts can't be used for any reason, I would change the answer. (No Mum I don't want to ...)
I removed the motor pin as it makes no sense for the answer. I also think that one pin would not be enough if your motor (stepper, dc with feedback or a servo) should spin a certain amount of degrees.
I tested the program on a Arduino UNO. The button I used is of low quality so I had to debounce it.
If there is something not clear to you, please ask within a comment.
// Attache the LED to a PWM pin UNO -> 3,5,6,9,10,11
const byte ledPin       = 9;

// UNO -> only pin 2 or pin 3 are interrupt pins
// as we use pullups the button should be connected to GND
const byte interruptPin = 2;

// in milli seconds - The time the LED needs to fully light up
const int timeFrame  = 5000;

// in milli seconds
const int aCoupleOfSeconds = 2000;

const int fadeAmount =    5;

volatile boolean fadeOn = false;
volatile long debounceTime = 800;
volatile long actTime = 0;

int brightness =   0;

int stepCount = 256       / fadeAmount;
int stepDelay = timeFrame /  stepCount;

void setup()
{
  pinMode( ledPin,       OUTPUT       );
  pinMode( interruptPin, INPUT_PULLUP );

  attachInterrupt( digitalPinToInterrupt( interruptPin ), pressed, CHANGE );
}

void loop()
{
  if ( fadeOn )
  {
    delay( stepDelay );
    brightness += fadeAmount;
    if ( brightness >= 255 )
    {
       brightness = 0;
       analogWrite( ledPin, brightness );
       delay( aCoupleOfSeconds );
    }
    analogWrite( ledPin, brightness );
  }
  else
  {
    brightness = 0;
    analogWrite( ledPin, brightness );
  }
}

void pressed()
{
  // the debouncing does not work perfectly

  if ( digitalRead( interruptPin ) == LOW )
  {
    if ( millis() - actTime > debounceTime )
    {
      fadeOn = !fadeOn;
    }
  }
  else
  {
    actTime = millis();
  }
}

"Our main problem is the fact that when we let go of the button the led turns off"

@Juraj Ahhhh, noo, I completely misread the question. Thank you for giving me the hint.

just change a boolean when button is pressed and from there build the code... if(switchstate == HIGH){bool1 = 1;} if(bool1 == 1){...}

@Hamed I have to synchronize the button if it is pressed longer. The OP does not want to hold the button. They press the button than the fading starts, if the LED is complete on, it should be switched off, waits a while and start again fading. If I press the button a second time I switch the LED and fading off. Just holding a boolean state would toggle if I press the button for a longer time. I plan to use interrupts.

millis() in cli()? it is incremented by a timer interrupt

@Juraj I' didn't really thought about that, but my prog. works fine. Perhaps it works because one can read the actual time when entering the ISR (cli block) but the time is not increased while the execution is in the ISR. (and that's not for very long). But because cli and sei don't have any impact of my program I can safely removed them to make it simpler. Thank you for the hint.

Have a look at some code inside the forum from marcello.romani. He posted it on jan 1st, 2013.
  The topic on subject is called : "button pressed more than 2 seconds do somethingelse"
  Marcello's code is so KISS (Keep It Simple Stupid) and efficient that it deserves a Nobel prize.
  The goals is to handle the different signals that come from a button or switch action :
  keyPress, keyRelease, longKeyPress etc.. as you can find in the original sketch.

The OP has no problem with longer or shorter key presses. She only wants to toggle a state by pressing the key. So the code might be good, but it does not answer the question. BTW: that code is for demonstration, and it is not KISS. "Do only the things that must be done". But for demonstration he uses methods with only one statement in it. I had to follow the execution path to find out what happens. No, that is not KISS, although IMHO it is perfect for demonstration purposes as he gives us the places where we can  extend it.


text:
Can I read from a memory card with three pins?
I have a project where I have three pins to use and I just realized it would be better to use a memory card than replacing the code each time.
I'm building a Arduino with a push button. Press the button and it sends keystrokes to the connected computer with login details.
The login details need to change every three months so having that on a memory card will be easier.
So since I use a digispark Attiny 85 with a total of 6 pins (where two is used to send the keystrokes).
I have one to the push button, and three pins left.
Is there any card reader that can work with three pins? I only need to read if that makes a difference.
The ones I find use four pins (+ vcc and gnd).
Pretty much any memory card type is ok.

Not with an ATTiny85, and not with so few pins, no.
However, all is not lost.
The ATTint85 has 512 bytes of EEPROM inside it where you can store your login details. All you need is some way of telling setting that data in your sketch from the PC - and the simplest way is probably through a USB serial connection.
If you don't have a serial connection available (I think Digispark has a custom interface they use) then you can use whatever interface you have available to do the job.

512 bytes is enough! Interesting! Is this fool proof? It's supposed to be normal people that does this. Not programmers or in any way tech savvy people.

Yes, it's foolproof. Not sur ewhat libraries are available for the attiny85, but the Arduino has the EEPROM library bundled with it...

I found this https://youtu.be/U9HEov6dDB8 not sure if it will work with digispark boards, but I will try it when I get them.

SD cards work with SPI. This needs only one pin per device (SlaveSelect) but 3 pins for the other common signals ( MISO / MOSI / SCK )
Card reader modules simply do some voltage level shifting (if at all).
But, you need a lot of RAM to work with SD cards, as data transfer always happens in 512 byte "sectors". With a file system, you need at least two such blocks in parallel. An attiny85 is simply too small.


text:
Using Arduino Wifi Shield to Receive Signal
I am trying to use an Arduino Uno with Arduino Wifi Shield 101 to receive a signal from phone or webpage over wifi so it will "initiate" my circuit. I was able to connect the board to wifi but am unsure on how I should continue. My main goal is to be able to send it two different commands that would run different parts of code in my arduino script. I am very new to this stuff! Thanks :)

use the arduino to serve a web page that has a button

Look for the Web Server example in the arduino IDE.  That will give you a starting point to allow you to control the arduino via a web page.  This tutorial is also very in depth : https://startingelectronics.org/articles/arduino/switch-and-web-page-button-LED-control/


text:
Will an Arduino Uno be able to read 3x incremental encoders?
Encoders are quadrature 600ppr encoders with X2 counting. Therefore 1200 counts per revolution for each encoder. Is there an edge rate limit? I currently have one encoder hooked up using code with interrupts.

The answer to the title's question is likely yes.  But I think your real question is how fast can (and you need to name a specific platform) a 16MHz Arduino Uno read a GPIO pin.

How fast are the encoders rotating?

Here is an example of some code I used to read two encoders using pin change interrupts.  This is possible to do with one ISR since they all share a common port.  The key is it has to be short.  As long as you can keep all 6 pins from your encoder on the same port, this should be easy to extend to 3 encoders.  It might even work for four on one port.  Or you can make a use a second port and get 3 or 4 more depending on which chip you have.
volatile uint8_t lastPortRead = 0;

volatile int32_t leftCounter = 0;
volatile int32_t rightCounter = 0;

ISR(PCINT2_vect){

    uint8_t portRead = PINC;

    uint8_t whoFired = portRead ^ lastPortRead;
    uint8_t pinsDiff = portRead ^ (portRead << 1); // Will have bits 5 or 7 set if pins on right motor or left motor are diff.  Cleared if same.

    if (whoFired & LEFT_INT_MASK) {
        if (pinsDiff & LEFT_INT_MASK) {
            leftCounter++;
        } else {
            leftCounter--;
        }
    }
    if (whoFired & RIGHT_INT_MASK) {
        if (pinsDiff & RIGHT_INT_MASK) {
            rightCounter++;
        } else {
            rightCounter--;
        }
    }

    lastPortRead = portRead;
}

The answer to the title's question is likely yes. But it would appear the real question is how fast can a given Arduino read a GPIO pin.
Consider there are multiple Arduino platforms.  Each possibly using a different type of processors.  Likely those processors are running at different speeds.  To give a specific answer we need to assume a specific platform, processor and speed.  The current (3rd generation) Arduino Uno runs at 16MHz.  And the Arduino Due runs at 84Mhz.  Since most people use an Arduino Uno let us use it for an example.
In this arduino.cc forum thread it is commented that an Arduino Uno running at 16MHz can execute the "Digital Pin Read" function call in about 4.78us.  Rounding that up to 5us that would be 1/5E-6 or 200000 samples per second.  Likely this can be improved upon if code were written to directly control the processors register for the desired outcome.  This is usually considered a moderately difficult embedded programming task.  And well outside normal Arduino knowledge.  In addition, such code would likely no longer be portable between different Arduino platforms.

there are tags arduino-uno and arduino-due on the question and Uno is in the title. so why the intro?

Good point.  I usually use tags for searching.  Didn't occur to me that tags were used to frame the question.  I'll reword the answer.

and that is in microseconds not milliseconds for digitalRead. "A digitalRead() is about 3.6us. "

You are correct.  Looking through that forum thread I only see the reference for 4.78us.  I edited the answer again and removed the mistake.

so "Will an Arduino Uno be able to read 3x incremental encoders?" (parallel)

Probably.  Or, to put it another way, it would appear unlikely the encoder would create more than 100000 cycles per second.


text:
Function parameter of type int not working as expected
I am attempting to write a small sketch with the Arduino IDE (1.8.10) to set the colour of an RGB LED, however my function for setting the colour of the LED is behaving strangely.
Here is the full sketch code:
#define RED 9
#define GREEN 10
#define BLUE 11

void setup()
{
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
  digitalWrite(BLUE, LOW);
  Serial.begin(9600);
}

int gRed = 20;
int gGreen = 21;
int gBlue = 22;

void setRGB(int r, int g, int b)
{
  Serial.println(r);
  Serial.println(g);
  Serial.println(b);
  analogWrite(RED, r);
  analogWrite(GREEN, g);
  analogWrite(BLUE, b);
}

void loop()
{
  //setRGB(gRed, gGreen, gBlue); // WORKS - White-ish
  setRGB(20, 21, 22); // DOESN'T WORK - Blue =/
}

As you may tell from the comments, when I pass "global" variables in to setRGB() the LED lights up the expected colour. But, when I pass literals in it does not.
The Serial monitor shows the following output when using the literals:
20
21⸮20
21
20
21
20
21⸮
etc....

Can anybody help me figure out what I'm doing wrong?
Board in use is a Mega2560.

Comments are not for extended discussion; this conversation has been moved to chat.

the conclusion in chat was a compiler problem (it over-optimized). with AVR core 1.6.21 which uses older version of avr-gcc the code worked

I'd add some delay between calls. Or even change the values by analogWrite when they changes only.


text:
How to connect MPU6050 to arduino using only digital pins
I am relatively new to Arduino and microchips, but I am good at electronics. I want to connect MPU6050 accelerometer+gyroscope module to Arduino. I searched on the internet and everywhere it is said to connect the SCL and SDA pins to two analog pins of the Arduino. As far as I know, the MPU6050 is a digital sensor, so why 2 analog pins are required for the sensor?
Also, is there any way to connect the sensor with only digital pins? because I need the analog pins for some other purpose.

The MPU6050 communicates over I2C. I2C uses clock line SCL and data line SDA. I2C pins on Uno are pins A4 and A5.
This is because the ATmega328p MCU used on Uno has the I2C peripheral on the same pins. It has nothing to do with the DAC function of the pins.
Alternatively MPU6050 can communicate over SPI. This are pins 11, 12, 13 on Uno and one more pin for CS. Pin 10 must be output while ATmega328p is SPI master so it is recommended to use it as CS for the SPI slave device.   EDIT Sorry, only MPU6000 has SPI.

I have noticed that there are separate SCL and SDA pins on the Arduino UNO. Can I use those?

@PuspamAdak, see the schematics. those are the same pins of the ATmega

@PuspamAdak, I enhanced the answer with information about SPI

Juraj, A0 and A1 and SCL and SDA are connected to the same pins on the ATmega processor? I would think that would cause confusion, since if you try to use I2C then A0 and A1 won't work as expected. What other pins are duplicates on the UNO? And what about the Mega 2560?

@DuncanC, A4 and A5, not A0/A1. yes it causes confusion. Mega has SDA SCL labels next to labels 20 and 21

Sorry, A4 and A5. Putting 2 different silkscreened labels on the same connector seems like a better idea than providing 2 different pair of connectors that actually map to the same pins internally. I wonder why the designers of the UNO did that?

So, I can't use the A4 and A5 pins while SCL and SDA are connected, isn't it?

@PuspamAdak, does your MPU6050 breakout board support SPI wiring?

How to check that?

what pins does it have?

VCC, GND, SCL, SDA, XDA, XCL, ADO and INT

Sorry, only MPU6000 has SPI.


text:
Compass heading not varying linearly
I am using an HMC-5983 magnetometer compass on my arduino uno to find the heading of a car I'm building.But my compass readings aren't varying linearly.For example when I physically turn my compass by 90 degrees the change in the reading doesn't correspond to 90 degrees.I tried mapping the raw output of the compass to the actual heading but when I do this , the headings in between the points I mapped aren't accurate enough thereby causing my car to behave abnormally.I also looked up on google but couldn't find anything helpful though there was some mention about using an algorithm to sort this issue.Please help me fix this problem.
    #include <Wire.h> //I2C Arduino Library
#define Magnetometer_mX0 0x03
#define Magnetometer_mX1 0x04
#define Magnetometer_mZ0 0x05
#define Magnetometer_mZ1 0x06
#define Magnetometer_mY0 0x07
#define Magnetometer_mY1 0x08
int mX0, mX1, mX_out;
int mY0, mY1, mY_out;
int mZ0, mZ1, mZ_out;
float heading, headingDegrees, headingFiltered, declination;
float Xm,Ym,Zm;
#define Magnetometer 0x1E //I2C 7bit address of HMC5883
void setup(){
  //Initialize Serial and I2C communications
  Serial.begin(9600);
  Wire.begin();
  delay(100);

  Wire.beginTransmission(Magnetometer);
  Wire.write(0x02); // Select mode register
  Wire.write(0x00); // Continuous measurement mode
  Wire.endTransmission();
}
void loop(){

//---- X-Axis
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mX1);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
    if(Wire.available()<=1)
  {
    mX0 = Wire.read();
  }
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mX0);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)
  {
    mX1 = Wire.read();
  }
  //---- Y-Axis
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mY1);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)
  {
    mY0 = Wire.read();
  }
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mY0);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)
  {
    mY1 = Wire.read();
  }

  //---- Z-Axis
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mZ1);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)
  {
    mZ0 = Wire.read();
  }
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mZ0);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)
  {
    mZ1 = Wire.read();
  }

  //---- X-Axis
  mX1=mX1<<8;
  mX_out =mX0+mX1; // Raw data
  // From the datasheet: 0.92 mG/digit
  Xm = mX_out*0.00092; // Gauss unit
  //* Earth magnetic field ranges from 0.25 to 0.65 Gauss, so these are the values that we need to get approximately.
  //---- Y-Axis
  mY1=mY1<<8;
  mY_out =mY0+mY1;
  Ym = mY_out*0.00092;
  //---- Z-Axis
  mZ1=mZ1<<8;
  mZ_out =mZ0+mZ1;
  Zm = mZ_out*0.00092;
  // ==============================
  //Calculating Heading
  heading = filtered_angle(Zm, Xm);// arc tangent of z/x

  // Correcting the heading with the declination angle depending on your location
  // You can find your declination angle at: http://www.ngdc.noaa.gov/geomag-web/
  // At my location it's 4.2 degrees => 0.073 rad
  declination = 0.03717551307 ;
  heading += declination;

  // Correcting when signs are reveresed
  if(heading <0) heading += 2*PI;
  // Correcting due to the addition of the declination angle
  if(heading > 2*PI)heading -= 2*PI;
  headingDegrees = heading * 180/PI; // The heading in Degrees unit
  // Smoothing the output angle / Low pass filter
  headingFiltered = headingDegrees;
  //Sending the heading value through the Serial Port to Processing IDE

  if(headingFiltered >= 0 && headingFiltered <= 89){
                c_head=map(headingFiltered,0,90,270,359);
        }
    if(headingFiltered > 89 && headingFiltered <= 204){
                c_head=map(headingFiltered,90,204,0,90);
        }
    if(headingFiltered > 204 && headingFiltered <= 290){
                c_head=map(headingFiltered,205,290,91,180);
        }
      if(headingFiltered > 290){
               c_head=map(headingFiltered,291,359,181,269);
        }

// Serial.print("Degrees - ");
 Serial.println(headingDegrees);
delay(500);
}

float filtered_angle(float p, float q) {
         const float filter_constant = 0.15;
         static float q_f, p_f; // filtered components
         q_f += filter_constant * (q - q_f);
         p_f += filter_constant * (p - p_f);
         return atan2(p, q);
        }

Can you give us a table with degrees, that you rotated, and the degrees, that you measured with them?

You are applying a non-linear (piecewise linear, with map()) transformation in your code. Why are you doing that? Why do you expect your non-linear transformation to yield a linear result?

If you can't find and eliminate a systemic error, such as nearby ferrous, magnetic, or electromagnetic sources, causing the errors you see, you'll need to do what navigators have done for ages: swing the compass.
Swinging a compass involves taking the vehicle - your robo-car - somewhere away from external error sources (building wiring, iron/steel masses, f/ex) and taking a set of measurements by heading the vehicle in a number of directions known by a means independent of its own compass. Eg., with a boat, you'd choose a known place in the middle of a harbor and plot a line from that known position to each landmark (for a car, you could use a large playing field). That gives you the True bearing (bearing relative to the north pole) from the chosen position to the landmark. Make a list of those landmarks and their true bearings in columns 1 & 2 of sheet of paper, in clockwise order starting a true north.
Convert the True bearings to Magnetic bearings (relative to the direction from where you are now to the earth's magnetic north pole): Navigation charts will show the difference (in degrees) between True bearings and magnetic bearings for the location(s) covered by that chart; the difference is called "variation" (sometimes called declination). If the magnetic variation at your location is westerly (compasses point 15 degrees W of True North, f/ex), add that value to those bearings you just listed. This third column of numbers is the magnetic bearing to each of those landmarks, and the value an error-free compass should read.
Now take your vehicle to that known point (playing field, middle of the harbor, etc.) and point its center line at each of those landmarks and read its compass for each one. Write these numbers in the fourth column - the compass headings to the landmarks, for this compass in this vehicle.
Columns 3 & 4 are now a compass correction table. When the compass reads a number that is in column 4 (compass bearing), the actual (corrected) magnetic heading is the corresponding number in column 3 (the magnetic headings).
But of course you don't have every possible heading in your compass correction table. So when you need to know your car's direction, you have to interpolate between a pair of bearings you do have:

Find a pair of bearings in column 4, the compass headings, that bracket the reading you just took.
Find the percentage that reading is of the difference between the bracketing compass bearings.
Apply that same percentage to the difference between the adjacent magnetic bearings in column 3 to find the actual magnetic bearing.

I glossed over the process of interpolation pretty quickly as the question was about correcting the compass. Interpolation, or other ways of applying a correction, is a whole 'nuther topic but the Arduino map() function will be great help here. Also, the more correction values (landmarks) you use to make your table, and the more evenly they are spread around the compass, the more accurate your corrections will be.

Thanks.it worked pretty well.I used the switch case control statement  and the map( )  function to get it done.


text:
Reset Arduino by connecting vcc and gnd?
A follow up question on my previous question, if a memory card reader can be used with three pins (digispark Attiny 85):
Can I read from a memory card with three pins?
Now I came up with another idea.
Since the USB connector or the VCC pin can power an Arduino my guess is that they are in parallel and the actual Arduino is connected to both.
Kind of like this very bad schematic made on my phone: (sorry for that)

Where the blue stuff is the Arduino chip.
If that is true then adding the push button between VCC and GND with a resistor between should remove the power of the Arduino?
In that case I can have my code in setup() and use the pus button to reset the Arduino, and still have four pins to the memory card reader.
Or is this wrong? What kind of resistor value do I need to make sure I don't short the USB connector but still have less resistance than the Arduino chip?

What's the problem with pulling the RST line down to GND? Shorting a supply is likely to kill it dead (or in the worst case blow it up and cause a fire).

@Dougie as far as I can see it doesn't have a reset pin

Then it ain't an Arduino. They even have a button on the board to ground the RST pin

@Dougie as i wrote in the question, it's a digispark Attiny 85. It doesn't have a reset button, and not even a dedicated reset pin. It's a pin that I need to use to the SD card reader

Yes it does pin#1 on the chip is the RST line. So can you change the description as it is NOT an Arduino.

It's quite common to use the name Arduino as board platform name, just like these does https://www.sparkfun.com/categories/242 . What is your point really? The question clearly state what device it is. Just as if I would ask a question about a pro mini vs mega, the pin layout and the count of pins is clearly different. No I can't use pin 1, as I wrote I need all the pins for a SD card reader.

That is wrong. That is very, very wrong. That is one of the worst things you can do to a USB connection short of plugging it into the mains.
Do not even consider doing this.  Short circuits are never a good idea.

Not even with a resistor?

Not even with a resistor. To make it "reset" you'd be having to cause the voltage to drop below the brownout threshold of the MCU. The only way that will happen is if you draw more current than the supply can give you. A good USB host will shut off the power to a port where that happens and alert you that it has a malfunctioning device. A bad one will just melt.

It's a good thing I asked then.. :-)


text:
Uno to NodeMCU Serial Connection Problem
This is my first project with any sort of development board and it has been a blast so far.
I am running into some issues, however, while trying to send serial data from my Uno to a NodeMCU board.
I have the following connections:
Uno Rx to NMcu Tx
Uno Tx to NMcu Rx
Uno GND to NMcu GND
microUSB from computer to power NMcu
usb from computer to power Uno
EDIT: after some suggestions, I have also tried the following.
Uno DigitalPin 5 to NMcu D6
Uno DigitalPin 6 to NMcu D5
Uno GND to NMcu GND
microUSB from computer to power NMcu
usb from computer to power Uno
With the following code:
// UNO sender Code
#include <SoftwareSerial.h>
SoftwareSerial toESP(0, 1); //Rx, Tx (also tried 5,6)

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

void loop()
{
  Serial.println("sending");
  toESP.println("message from Nano");
  delay(1000);
}

// NodeMCU receiver code
#include <SoftwareSerial.h>
SoftwareSerial fromNano(3, 2); //Rx, Tx (also tried D5, D6)

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

void loop()
{
  if (fromNano.available())
  {
    char inChar = fromNano.read();
    Serial.print(inChar);
  }
  else {
    Serial.println("not available");
  }
  delay(2000);
}

I can pull up a serial monitor from both and see the UNO sending data (the TX led also blinks on the uno).
The NodeMCU code never satisfies the fromNano.available condition.
Is there anything I am overlooking that is causing this not to work? I've attached a picture of my connections as well.

Any help is much appreciated.

0 and 1 are hardware Serial pins in Uno and 3 is a hardware Serial pin on NodeMcu so you should not use it for SoftwareSerial. and the wires are on pins 1 and 3 on NodeMcu (hardware Serial pins)

Hmm, thanks for the response. I tried using other digital pins on the arduino and nodemcu (and made sure to update the corresponding code) the other night, but didn't have any luck. I tried something like SoftwareSerial(5,6) for the sender (arduino) and SoftwareSerial(D5,D6) for the receiver (nodeMCU). Making sure that arduino digital pin 5 is connected to nodemcu D6, and vice versa. I'll try again later tonight.

@Juraj - After trying on digital pins 5,6 on the arduino, and D5,D6 on the nodemcu, I still cannot receive serial data. fromNano.available() is always false. I've set both to 9600 baud rate. https://imgur.com/a/gfVo2nt

Arduino UNO is using pin 0 and pin 1 to have serial with USB serial Communication. You can not use them to softserial. Change softserial to other pins.  /Mikael

Thanks for the comment. Is it fine to just use any other digital pins to initialize the SoftwareSerial?

I tried digital pins 2 and 3 (and also 5,6) for RX,TX respectively and it didn't seem to solve the issue. Thank you for the suggestion though.

Why do use 2 serial conections, you only need one.

I'm only using one serial connection between the boards from my understanding. I just tried on pairs (2,3) and (5,6) independently for troubleshooting.

In the code you are using two.

Are you referring to Serial vs SoftwareSerial? I am including a Serial channel to debug via the monitor in Arduino IDE

Is the Arduino 5V or 3V? The NodeMcu is not always 5V tollerant. Try to remove the USB connection from the Arduino then connect 3V from NodeMcu to 5V on the Arduino.

@Carlmikael is definitely correct in his answer, I should not have been using hardware pins with softwareserial.
Besides that problem, my issue was resolved ultimately when I noticed that if I powered up the NodeMCU before powering up the Arduino, everything worked as expected.
Maybe someone can elaborate as to why this caused an issue?


text:
Some Blocks of Code gets stuck in a loop, I do not know why

The code below Gets stuck at function "Led Off?" & "Check button".
I'm using Blockyduino editor.
The check button code was intended as a toggle switch for the lights. When I deleted "Led Off?" and "Turn off All LED", the code did not get stuck.
int Button_Status;

// Toggle Code for the button.
void Check_Button() {
  Serial.println("Check button Activated");
  if (Button_Status == 1) {
    if (digitalRead(13)) {
      Button_Status = 0;
    }
  }
  if (Button_Status == 0) {
    if (digitalRead(13)) {
      Button_Status = 1;
    }
  }
  LED_OFF_();
}

void Left_Animation() {
  Check_Button();
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  Check_Button();
  delay(1000);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  Check_Button();
  delay(500);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  Check_Button();
  delay(300);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  Serial.println("Finshed Left cycle");
}

void Right_Animation() {
  Check_Button();
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  Check_Button();
  delay(1000);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  Check_Button();
  delay(500);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  Check_Button();
  delay(300);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  Serial.println("Finished Right cycle");
}

// Main Loop Core
void Main_Loop() {
  while (Button_Status == 1) {
    Left_Animation();
    Right_Animation();
    Serial.println("Finshed Main Loop 1111");
  }
  while (Button_Status == 0) {
    Check_Button();
    Serial.println("Finished Main Loop 2222");
  }
}

// Checks if button toggle variable is off.
void LED_OFF_() {
  Serial.println("LED off? Activated");
  if (Button_Status == 0) {
    Turn_Off_All_LED();
  }
  Main_Loop();
}

// Turns off all LED
void Turn_Off_All_LED() {
  Serial.println("LED Turn off Activated");
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  Main_Loop();
}

void setup()
{
  Serial.begin(9600);
  pinMode(13, INPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop()
{
  // Start
  Button_Status = 1;
  Main_Loop();
}

You have a problem with infinite recursion in this program: loop()
calls Main_Loop(), which calls Left_Animation(), which calls
Check_Button(), which calls LED_OFF_(), which calls Main_Loop(),
which calls Left_Animation(), which calls Check_Button(), which
calls LED_OFF_(), which calls Main_Loop(), which calls... This will
pretty quickly exhaust the memory of your Arduino.
If you only know about graphical programming, this may not make too much
sense to you. So I ask you to imagine that, in your definition of
Main_Loop() (the big structure titled “to Main Loop”) you replace the
smallish box labeled “Left Animation” by its own definition (the big
structure labeled “to Left Animation”). Within this definition, you
replace “Check Button” by its own definition and so on. You will soon
reach a point where you need to embed the definition of Main_Loop()
within itself. It should then look more or less like this:
Main Loop
│ repeat while Button Status = 1
│ do Left animation
│ │  │ Check Button
│ │  │ │ Serial Print “Check button Activated”
│ │  │ │ ...
│ │  │ │ LED OFF?
│ │  │ │ │ Serial Print “LED off? activated”
│ │  │ │ │ if Button Status = 0
│ │  │ │ │ do Turn Off All LED
│ │  │ │ │ Main Loop
│ │  │ │ │ │ repeat while Button Status = 1
│ │  │ │ │ │ do Left animation
│ │  │ │ │ │ │  │ Check Button
│ │  │ │ │ │ │  │ │ Serial Print “Check button Activated”
│ │  │ │ │ │ │  │ │ ...
│ │  │ │ │ │ │  │ │ LED OFF?
│ │  │ │ │ │ │  │ │ │ Serial Print “LED off? activated”
│ │  │ │ │ │ │  │ │ │ if Button Status = 0
│ │  │ │ │ │ │  │ │ │ do Turn Off All LED
│ │  │ │ │ │ │  │ │ │ Main Loop
│ │  │ │ │ │ │  │ │ │ │ repeat while Button Status = 1
│ │  │ │ │ │ │  │ │ │ │ do Left animation
│ │  │ │ │ │ │  │ │ │ │ │  │ Check Button
│ │  │ │ │ │ │  │ │ │ │ │  │ │ Serial Print “Check button Activated”
│ │  │ │ │ │ │  │ │ │ │ │  │ │ ...
│ │  │ │ │ │ │  │ │ │ │ │  │ │ LED OFF?
│ │  │ │ │ │ │  │ │ │ │ │  │ │ │ Serial Print “LED off? activated”
│ │  │ │ │ │ │  │ │ │ │ │  │ │ │ if Button Status = 0
│ │  │ │ │ │ │  │ │ │ │ │  │ │ │ do Turn Off All LED
│ │  │ │ │ │ │  │ │ │ │ │  │ │ │ Main Loop
...etc ad infinitum...

Note that it is possible to write programs using recursion, but:

This is kind of an “advanced topic”, not suitable for someone still
programming at a graphic level.
You have to take precautions in order to avoid the program to
infinitely recurse.
On a microcontroller with little memory, you have to make sure the
recursion is always very shallow. Which is hard, so people writing
embedded code tend to avoid recursion altogether.


text:
Problem burning bootloader to ATmega chip using nano/uno
I designed a custom PCB that has the chip, an oscillatorm, decoupling capacitors, and all other connections for the ATmega along with the rest of my circuit. I followed all steps in the tutorial for burning the bootloader to my ATmega chip but when using a nano to program I get an error about getsync() that supposedly means the reset isnt working. I then used the same wiring with an uno like in the examples and I got a different error this time where it goes yikes then something about not recognizing the chip. This is apparently indicative of a wiring or oscillator problem but all those things appear to be correct. I'm not sure what to try next or what could be wrong
Used this tutorial as well as the actual arduino page https://www.electronoobs.com/eng_arduino_tut6.php
Used this tutorial next since I am using ATmega328PB
https://www.circuito.io/blog/atmega328p-bootloader/
Here's the error I get
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "ATmega328, Yes (UART0), 328PB, BOD 2.7V, LTO disabled, 16 MHz external"
\nas01.itap.purdue.edu\puhome\My Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -C\nas01.itap.purdue.edu\puhome\My Documents\ArduinoData\packages\MiniCore\hardware\avr\2.0.3/avrdude.conf -v -patmega328pb -cstk500v1 -PCOM5 -b19200 -e -Ulock:w:0x3f:m -Uefuse:w:0b11110101:m -Uhfuse:w:0xd6:m -Ulfuse:w:0b11111111:m
avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch
     System wide configuration file is "\\nas01.itap.purdue.edu\puhome\My Documents\ArduinoData\packages\MiniCore\hardware\avr\2.0.3/avrdude.conf"

     Using Port                    : COM5
     Using Programmer              : stk500v1
     Overriding Baud Rate          : 19200
     AVR Part                      : ATmega328PB
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PC2
     RESET disposition             : dedicated
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
       flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
       lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

     Programmer Type : STK500
     Description     : Atmel STK500 Version 1.x firmware
     Hardware Version: 2
     Firmware Version: 1.18
     Topcard         : Unknown
     Vtarget         : 0.0 V
     Varef           : 0.0 V
     Oscillator      : Off
     SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0xffffff (retrying)
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0xffffff (retrying)
Error while burning bootloader.
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0xffffff
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.
avrdude done.  Thank you.
Here's the PCB schematic and wiring picture

Post a link to the tutorial that you followed.

Edited original post to add tutorial

The tutorial is fine, except for reset pin which he should've used a 10K resistor. post the exact error message(s) and a picture of what you have on breadboard or PCB...

Updated again, added new tutorial I tried and the pictures

I had the same "invalid device signature" problem and using minicore library solved it. if you followed all steps correctly, maybe the chip is damaged.

Yeah I replaced the chip and then was able to burn the bootloader fine. But now when programming I get an error that programmer isn't responding. I'm using this guide: https://www.instructables.com/id/Program-ATmega-328-Using-Arduino-Arduino-As-ISP/


text:
I want to send the last 10 minute data via bluetooth
This was for photocell data logging for 30 sec intervals, now I want to write a code which commands from the cellphone and sends back the last 10 minute data.
At first I thought if I make an array of 20 buckets and put it in a loop, then send the loop function to android would make it right. But it just sends me continues data. I only want the last 10 minute data of the program.
float sensorvalue[20];

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(9600);

    for (int i = 0; i < 20; i++) {
        pinMode(sensorvalue, OUTPUT);
    }
}

void loop()
{
    // put your main code here, to run repeatedly:
    sendvalues();
    char c;

    if(Serial.available()) {
        c=Serial.read();
        if (c=='t')
            sendvalues();
    }
}

void sendvalues()
{
    for (int i=0 ; i<20 ; i++) {

        Serial.println(sensorvalue);
        sensorvalue   = analogRead(A0);
        delay(30000); //every 30 seconds read data

        if (i>=20) {
            i=0; //reset to beginning of array, so you don't try to save readings outside of the bounds of the array
        }
    }
    Serial.println("***********************************");
}

it reads every 30 seconds. i want to send the last 10 minute data but i'm not sure this is the right way...

you really should format your code ... it is practically unreadable

If you want to get/send last 10 minutes of data; first you(your code) have to know how long the transmit is gonna be, and then you can use millis() function or an RTS chip to define exactly when you want the data to be sent. basically a count down timer, start for example from 20 minutes and when it reached 10 minutes starts sending the data.

Thank you so much. The idea of count down sounds fine, but i have one problem. I should receive the last 10 minute data whenever i send for example "m" from my serial port.

well then start counting whenever you send the letter "m".

I don't want live data and that's the problem. I need the data that was measured 10 minutes before i send the command. it's either confusing or i'm not on the right road...

What you want for this project is called a ring buffer. Before
reading the rest of this answer, I suggest you stop and take the time to
carefully read the Wikipedia page I am linking to.
Did you read it? Good! Now, yours is a somewhat special case in that you
don't need to continuously keep track of both a read pointer and a write
pointer: you only need the write pointer, as the read happens all in one
big batch.
Once your ring buffer is full, you will start overwriting the oldest
readings, those that are more than 10 minutes old. When the program
is instructed to dump the data, it will send out the whole buffer,
starting with the cell pointed to by the write pointer (the cell that
holds the oldest data point and was about to be overwritten).
There is one special case to take care of. What if the program gets the
command to dump the data while it has less than 20 readings stored?
You could decide that this is a user error, and it's OK for the program
to give garbage. I suggest, however, that the program should be able to
detect this situation, and then only send the valid data. For this, it
needs to store a boolean variable in order to remember whether the
buffer has been filled or not.
Here is an implementation I propose for such a ring buffer, together
with the functions for adding an item and for dumping all the data
through the serial port:
const uint32_t READING_PERIOD = 30000;  // one reading every 30 s
const int MAX_READINGS = 20;           // 20 readings = 10 min

int readings[MAX_READINGS];  // ring buffer
uint8_t reding_index = 0;    // next available slot
bool readings_full = false;  // did we fill the ring buffer?

static void register_reading(int value) {
    readings[reding_index] = value;
    if (++reding_index >= MAX_READINGS) {
        readings_full = true;
        reding_index = 0;
    }
}

static void dump_readings() {
    // If the buffer is full, then the next avaiable slot is the oldest
    // reading in the buffer.
    if (readings_full) {
        for (int i = reding_index; i < MAX_READINGS; i++)
            Serial.println(readings[i]);
    }
    for (int i = 0; i < reding_index; i++)
        Serial.println(readings[i]);
}

Now the main program is quite simple. You time the data taken using the
technique shown in the Blink without delay tutorial. You don't want
to use delay() because, when the program is delaying, it cannot
respond to your commands. There is one last question remaining: when it
dumps the data, should it forget it? In other words, if you ask it twice
to dump the data, with less that 10 minutes in between, should it
give repeated data the second time, or should it only provide the fresh
data? In the code below I assume the later option, and thus reset the
buffer, but in the end it is your choice:
void setup() {
    Serial.begin(9600);
}

void loop() {
    // Periodically take a reading.
    static uint32_t last_reading_time;
    if (millis() - last_reading_time >= READING_PERIOD) {
        last_reading_time += READING_PERIOD;
        register_reading(analogRead(A0));
    }

    // Dump the data on command.
    if (Serial.read() == 't') {
        dump_readings();
        reding_index = 0;       // reset the buffer
        readings_full = false;  // ditto
    }
}

thank you so much!!!! I've been stuck in this code forever... I think it was too heavy for a newbie..lol

Can you edit your question to better explain what you want to do?

Your code doesn't make much sense as written.
You need to:
Collect a new value every 30 seconds and save it into an array of values, incrementing a "current value index" variable with each read.
Do you want to trigger the sending of a buffer-full of data when the array is full, or using a command from the remote phone? If you want to trigger the sending from a phone, what would you do if there wasn't a full buffer of data? What would you do if the buffer gets full and there's no command sent from the phone?
Assuming you send a buffer-full of data every time it's available, just wait until the array index reaches the end. When that happens, transmit the entire buffer of data to your phone and reset the array index to start collecting new data.
If you want to trigger sending from your phone you have to handle edge cases like buffer overflow, or trying to send before you have a full buffer of data. I would suggest creating an array larger than you need (say 100 values), making it a ring buffer (google it) and saving new values continuously until the ring buffer is full. If the sketch receives a send command, it could check to see if it has at least 20 values in the buffer, and send those/remove them from the buffer if it does, or send back a "not enough data collected" message if not.

thank you so much :)