Error digitalRead from char

Hi,

I want to read the digital pins from a given number of connections. Since the name of those numbers does not follow a consecutive order, I had to define an array. Those names start with PR and a the number. I've achieved to print on the screen the names correctly like PR5, PR6, PR7.... using the sprintof command. However, I cannot use the char buffer (where the names are located) to read the digital pin value. I got the following error:

C:\Users\ In function 'void loop()':

C:\Users\:100:36: warning: invalid conversion from 'char*' to 'uint8_t {aka unsigned char}' [-fpermissive]

           read = digitalRead(buffer);

                                    ^

In file included from sketch\Master_Tester_TX.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:135:5: note:   initializing argument 1 of 'int digitalRead(uint8_t)'

 int digitalRead(uint8_t);

     ^

Find the code below. Note that those digitalRead functions inside a For loop are placed inside a Switch case.

int read;
x_arr = new int[15] {5, 6, 7, 9, 10, 11, 15, 16, 17, 21, 22, 23, 25, 26, 27};
      x = 15;
     
      if (digitalRead(buttonStart) == HIGH)
      {        
        char buffer[32];        
        
        for (int i = 0; i < 15; i++) {
          int s = x_arr[i];
          sprintf(buffer, "PR%d", s);          
          read = digitalRead(buffer);          
          delay(delay_);
        }
      }

I've also tried to convert the buffer (char) into uint8, but it does not work.

How can I solve this?

Thanks

Thank you for using code tags. But please read the forum guide in the sticky post in full and then modify your post above and fix it.

Using a string as the parameter to digitalRead() is nonsense. Please describe what you are trying to do in more detail. Please do not try to use technical words that you may not understand. Just use pain English.

I can't be sure, but perhaps you meant

          read = digitalRead(s);

Why Your buffer is empty? And why You use char for that?
Did You use arduino? Or another platform?

Normally on arduino
" arraypin[] = {A0, A1, A2,A3}; " is working properly, and using
" int mew = analogRead(arraypin[2]); " should not have any problems.

In Your code, U=You try read from array what dont have any value in side. Is empty.

Ps, if You want convert string from keyboard, Use function " String(data) "
like:
" string words;
int value;
words = String(value); "

converts value to the character alfabet.
" int x;
char w;
w = char(x) "

converts character to integer.
" char w;
int x:
x = int(w); "

This way

buffer is a character array; why do you use it in the digitalRead that takes an int as a parameter? x_arr is the array with the pins (and is of type int); you can use it directly.

Without seeing the full code, be aware that when using the new keyword, you also have to delete the array; else you have a recipe for exhausting your memory.

Maxim2511, how should I define the array? int or char? I got an error about it.

Hmmm, what are you actually putting into this array?

Oh yes, characters, from a serial input.

Well, that just happens to be what "char" means!

Also same as 8-bit bytes.

I know it is char. Using this line

char *arraypin [] = {"PR5", "PR6", "PR7", "PR9", "PR10", "PR11", "PR15", "PR16", "PR17", "PR21", "PR22", "PR23", "PR25", "PR26", "PR27"};

But it does not work.

Note that I'm defining the char array inside a switch case statement inside the void loop.

Then something else is wrong. Simple as that.

REM14:
I know it is char. Using this line

char *arraypin [] = {"PR5", "PR6", "PR7", "PR9", "PR10", "PR11", "PR15", "PR16", "PR17", "PR21", "PR22", "PR23", "PR25", "PR26", "PR27"};

But it does not work.

Note that I'm defining the char array inside a switch case statement inside the void loop.

Maybe time to post your complete code. And tell us which board you're using.