Beginner question: using strings to control pins

Hello,

I'm just starting with Arduino with some experience in other languages (but little in C++). I'm sorry if this question should be asked somewhere else, I did the obligatory searching through this forum and others, but couldn't find anything to help out.

Basically I'm trying to write code that, based on a variable will control LED's connected to different pins. As the code currently stands, the variables I'm using are Strings. I imagine this is the root of my problem, but don't know what to do about it.

An example bit of code is:

int Rled1 = 12;
int Rled2 = 11;

void Setup(){
  pinMode(Rled1, OUTPUT);
  pinMode(Rled2, OUTPUT);
}
void loop(){
  //i have a segment of code here I can confirm is working, through the serial monitor.  get's me to:
  if (var == 1){
    String red_led = "Rled";
    red_led.concat(var); //up till here works
    digitalWrite(red_led, 255);
  }
}

The last line of my code gives the error: " cannot convert 'String' to 'uint8_t' for argument '1' to 'void digitalWrite(uint8_t, uint8_t)'".

Any help would be greatly appreciated.

Thanks

The Arduino has no idea that the String "Rled1" has anything to do with the int variable Rled1. All the Arduino knows about Rled1 is that it is 2 bytes and has an address. You need to create a Hash table or use a series of if/else statements.

Thanks Archh. I guess what I'm getting at is: Is there any way to use a variable to assign which pin to control? If so, am I able to use/convert a string to be this variable?

Again, thanks.

Hainsy: Is there any way to use a variable to assign which pin to control?

Yes.

If so, am I able to use/convert a string to be this variable?

Again, thanks.

I just answered that in my last post.

Thanks again... you made me realize the far easier way was to use arrays where the call variable was equal to the pin to call.