Hey all, I'm very new to c++ and feel what I'm trying to do should be pretty straight forward, however I've been unable to find any information as to how to do this or if it is actually possible. In my code I want to pass a number to a function, have the function then use that same number to modify a variable name that the function uses.
Here's the idea for my code.
const int r1 = 11;
const int r2 = 5;
const int r3 = 4;
const int r4 = 10;
const int y1 = 12;
const int y2 = 6;
const int y3 = 3;
const int y4 = 9;
const int g1 = 13;
const int g2 = 7;
const int g3 = 2;
const int g4 = 8;
char r = r;
char y = y;
char g = g;
void setup(){
for(int x = 0; x<14; x++){
pinMode(x, OUTPUT);
}
}
void turnon(int lightnum){
digitalWrite(r+lightnum, HIGH);
digitalWrite(y+lightnum, HIGH);
digitalWrite(g+lightnum, HIGH);
}
void loop(){
turnon(1);
}
I would like this to make the pins I've named r1, y1, and g1, all go high.