PaulS:
Lets be smart and say the switch is connect to D5 and ground, and that we'll use the internal pullup resistor.
That is already what I am basing my final design on.
However, in developing the code, I found that when using the internal pull-up, the status of the pin cannot be manipulated with digitalWrite. So I am starting off without internal pull-up so I can do a soft simulation.
CrossRoads:
I would think something like this would work.
CrossRoads, I have a version of test code that is very similar to yours viz.
#define conf_Optional // conf_1 / conf_2 / conf_Optional
#define pinConf 5 // Ext switch input
char conf[7];
int pinConf_state = LOW;
void setup() {
Serial.begin(9600);
Serial.println("Serial Started!");
#ifdef conf_Optional
// pinMode(pinConf, INPUT_PULLUP);
pinMode(pinConf, INPUT); // for soft simulation
pinConf_state = (digitalRead(pinConf));
Serial.print("1 : ");
Serial.println(pinConf_state);
//digitalWrite(pinConf, HIGH); // uncomment to simulate soft switch
//delay(25);
pinConf_state = (digitalRead(pinConf));
Serial.print("2 : ");
Serial.println(pinConf_state);
if (pinConf_state == 0) strcpy(conf, "conf_1");
else strcpy(conf, "conf_2");
Serial.print("Conf : ");
Serial.println(conf);
#endif
/*
#ifdef conf_Optional
if (conf == "conf_2") #include <Ethernet.h>;
#endif
*/
}
void loop() {
}
The caveat, is that for config 2, I want to include the Ethernet Library and this code won't do it since it is being done in setup.
In theory I need something the equivalent of the below in the header section...
#ifdef lan_Optional
int pinLan = 5; // Ext switch input
pinMode(pinLan, INPUT);
// digitalWrite(pinLan, HIGH); // uncomment for soft switch test only
if (digitalRead(pinLan) == HIGH) define lan_Ethernet;
#endif
The above of course won't work, hence my question about .c and .cpp tabs since they are compiled separately.
The only other idea I can think of is to write a pin 5 state change to EEPROM then use that during the next boot-up to determine the config.