How do I pass string variable into function

How do I pass string variable into function

I have function call as follows

binary_string(15,"0111000000111111000011000000");

with this function

void send_binary_string(int A2, char* A5) 
   {
      int a = 0; while( a < A2 ) {  a++;  
        Serial.println(" ");Serial.print(", ");Serial.print(a);Serial.print(", ");Serial.print(A5);Serial.print(", ");
        digitalWrite(0,HIGH); delayMicroseconds(A3);digitalWrite(0, LOW); delayMicroseconds(A4);
         //unsigned char *word = A55;
         //strcpy("A55", "A5");
        char *word = "A5";
          for(int i = 0; word[i]; i++) { 
            if (word[i] == '1') { 
              // "1" long high + short low
              digitalWrite(0,HIGH); delayMicroseconds(A6); digitalWrite(0, LOW); delayMicroseconds(A7);  Serial.print("1");
                                } else {  
              // "0" short high + long low
              digitalWrite(0,HIGH); delayMicroseconds(A7); digitalWrite(0, LOW); delayMicroseconds(A6);  Serial.print("0");
                                      }
                                        }
           Serial.println(" "); }
    }

I can’t get the semantics for the string right. I know it’s going in because Serial.print(A5) prints it to the serial monitor. I have tried changing the function definition for the string to just about everything I can think of, eg
char* A5
String A5
char *word A5
std:string A5
etc etc
I have tried strcpy as shown too.

I know it’s not being pulled into char *word = “A5”; because
Serial.print(“1”); and
Serial.print(“0”);
are outputting nothing on the serial monitor.

But if I remove the variable A5 from the function and the call and replace A5 with
“0111000000111111000011000000”
it works.

Any help please?

Oh my gosh: for Heaven’s sake, please format your code correctly. Your indentation and other parts of code are way off.

Code like this:

void send_binary_string(int A2, char* A5) 
   {
      int a = 0; 

      while( a < A2 ) 
      {  
         a++;  

         Serial.println(" ");
         Serial.print(", ");
         Serial.print(a);
         Serial.print(", ");
         Serial.print(A5);
         Serial.print(", ");

         digitalWrite(0,HIGH);
         delayMicroseconds(A3);

         digitalWrite(0, LOW); 
         delayMicroseconds(A4);

         //unsigned char *word = A55;
         //strcpy("A55", "A5");
         char *word = "A5";

         for(int i = 0; word[i]; i++)
         { 
            if (word[i] == '1')
            { 
               // "1" long high + short low
               digitalWrite(0,HIGH);
               delayMicroseconds(A6);

               digitalWrite(0, LOW); 
               delayMicroseconds(A7);  

               Serial.print("1");
            } 
            else 
            {  
               // "0" short high + long low
               digitalWrite(0,HIGH); 
               delayMicroseconds(A7);

               digitalWrite(0, LOW);
               delayMicroseconds(A6);
               Serial.print("0");
            }
         }
           Serial.println(" ");
      }
   }

Isn’t The above code so much easier to read?

As to answer your question, why not just create the string outside of the function call and then pass the pointer?

To avoid confusion, I'd think carefully about variable names that look like analogue pin numbers.

The name of the variable, A5, is NOT in any way, shape, or form, related, at run time, to the string "A5". It really isn't clear what you are trying to do with the string you passed in.

Change "      char *word = "A5";" to "    char *word = A5;" ?

MarkT: Change "      char *word = "A5";" to "    char *word = A5;" ?

Thanks Guys for the ideas and MarkT for the solution. Just removing those quotes around char *word = "A5"; did it.

You are doing digitalWrite() to pin 0 which is one of the two Serial pins on an Arduino UNO. You should not do that when you are trying to use Serial.

Using the names of various analog input pins (A0, A1, A2, A3, A4, A5) as variable names is confusing. Especially when you leave out the part of the sketch that defines those names.

Why use:

 int a = 0;
  while ( a < A2 ) {
    a++;

when you could probably use:

 for (int a=0; a < A2, a++) {

Power_Broker: As to answer your question, why not just create the string outside of the function call and then pass the pointer?

If you define the variable outside the function, you don't need to pass anything. However, making data global simply because you don't know how to pass a pointer is not the right way to solve the problem. The better way is to learn how to use pointers properly. Also, instead of using global data, a better way is to define the string inside the function, minimizing outside contamination, and then simply pass the array to the function.

econjack: If you define the variable outside the function, you don't need to pass anything. However, making data global simply because you don't know how to pass a pointer is not the right way to solve the problem. The better way is to learn how to use pointers properly. Also, instead of using global data, a better way is to define the string inside the function, minimizing outside contamination, and then simply pass the array to the function.

No, no, no.

I'm not saying to use a global variable, I'm just saying that you can initialize the array outside the scope of the function in question (but still not global - i.e. initialize the string in loop() or another user defined function instead of outside all functions) and then pass the pointer (which would still be required since it isn't a global variable).

What everyone else said: do not use 'A5' as a variable name in arduino code.

First: it's used by the platform itself as being the pin number of analogue input 5.

Second: it means nothing.

Use 'delayShort_us' and 'delayLong_us', for instance. Now you know what they are: a short and a long delay measured in microseconds.