I have spent hours trying to find the answer here and by Google, thanks in advance for any help you may offer me.
I am trying to use a string to refer to my predefined output pins. I call them JET1 through JET10 and I want to loop through them using a for loop. I then concatenate the string "JET" with the variable jet to give me the same labels as defined up top.
It won't compile no matter what I try. The error message is "cannot convert 'String' to 'uint8_t {aka unsigned char}' for argument '1' to 'void digitalWrite(uint8_t, uint8_t)' "
I have chopped this up to make it easier to understand.
A|What do I have to do to refer to a label this way? TIA
That's not going to work. Al your defines are ONLY used when compiling. Before it compiles it kind of does a big search and replace for every define in the code. So it will not find anything. After that it forgets about them so when running the code it does nothing.
There are more logical ways of doing something like that. And for that matter you just want to stay away from the awfull String class.
An example:
const byte JetPins[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
void setup(){
for(byte i = 0; i < sizeof(JetPins); i++){
pinMode(JetPins[i], OUTPUT);
}
}
void loop(){
for(byte i = 0; i < sizeof(JetPins); i++){
digitalWrite(JetPins[i], HIGH);
}
delay(1000);
for(byte i = 0; i < sizeof(JetPins); i++){
digitalWrite(JetPins[i], LOW);
}
delay(1000);
}