What would be the benefit in this case to using an array? Any numbers as arguments coming from MQTT that go into the function can't be used as an array index anyway since they're char
static const uint8_t digitalPins[] = {D0, D1, D2, D3, D4, D5, D6, D7};
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(digitalPins[i], OUTPUT);
}
}
// pinNumber could be "1" and state could be "HIGH"
void controlRelay(const char* pinNumber, const char* state) {
if(strcmp(state, "LOW") == 0){
digitalWrite(digitalPins[pinNumber], LOW)
} else if (strcmp(state, "HIGH") == 0){
digitalWrite(digitalPins[pinNumber], HIGH)
} else {
// error handling
}
}