I have some arrays which all have a similair var name. Underneat I have a "final" array which lists all the arrays which are active at that setup. In the part 'Setup active ports' it will go over all the elements in the "final" array. It should then get values (like the label or pin number) from the array with that name. So where 'THIS IS WHERE THE MAGIC (SHOULD) HAPPEN' is, it should print '22' for the first, and '23' for the second. However, it's giving me the second character ('sp_sw3' = 'p') of the name of the array, instead of the second array value.
// Relay list
char sp_sw3[][32] = { "Light", "22" };
char sp_sw4[][32] = { "Fan", "23" };
// IR list
char sp_ir8[][32] = { "TV", "00x1acb", "04x74gx" };
char sp_ir9[][32] = { "HDMI", "02x2dds", "20x1wsb" };
// Active list
char sp_active[][8] = { "sp_sw4", "sp_sw3", "sp_ir8" };
// General settings
int serial_baud = 9600;
int pin_led = 13;
/* ---------------------------------------------------------------- */
// Setup
void setup() {
// Setup serial
Serial.begin(serial_baud);
Serial.print("SETUP: Serial communication initiated (");
Serial.print(serial_baud);
Serial.print(" baud).\n");
// Setup LED pin
pinMode(pin_led, OUTPUT);
digitalWrite(pin_led, HIGH);
Serial.print("SETUP: LED pin is declared on pin '");
Serial.print(pin_led);
Serial.print("'.\n");
Serial.print("INFO: LED is ON during setup and goes OFF when completed.\n");
// Setup active ports
for (byte sp_idx = 0; sp_idx < sizeof(sp_active) / sizeof(sp_active[0]); sp_idx++) {
String sp_check = sp_active[sp_idx];
if (sp_check.startsWith("sp_sw")) {
Serial.print("SETUP: List item '");
Serial.print(sp_check);
Serial.print("' is declared on pin '");
// THIS IS WHERE THE MAGIC (SHOULD) HAPPEN
Serial.print(sp_check[1]);
// THIS IS WHERE THE MAGIC (SHOULD) HAPPEN
Serial.print("'.\n");
} else {
Serial.print("SETUP: List item '");
Serial.print(sp_check);
Serial.print("' does not need to do anything during setup.\n");
}
}
// Setup completed
delay(1000);
digitalWrite(pin_led, LOW);
Serial.print("SETUP COMPLETED!\n");
delay(1000);
}
/* ---------------------------------------------------------------- */
// Loop
void loop() {
delay(1900);
digitalWrite(pin_led, HIGH);
delay(100);
digitalWrite(pin_led, LOW);
}