Shield Versioning

See the code in action on Tinkercad

/*
Simple method to set a number between 0 and 7
Dip switch pin 4 enables or disables the voltage coming from A3
*/

#define MEGABoard

uint8_t shieldVersion = 0;
//Shield Version Pins
#ifdef MEGABoard
  #define testPIN    A4          //Used to Trigger Shield Version ID
  #define verPIN0    A3          //Used to ID Shield Version 1s bit
  #define verPIN1    A2          //Used to ID Shield Version 1s bit
  #define verPIN2    A1          //Used to ID Shield Version 2s bit
  #define verPIN3    A0          //Used to ID Shield Version 4s bit
#endif

void setup() {
  Serial.begin(9600);
  #ifdef MEGABoard
    pinMode(verPIN0, INPUT);      //Used for Shield Versioning bit value 1
    pinMode(verPIN1, INPUT);      //Used for Shield Versioning bit value 2
    pinMode(verPIN2, INPUT);      //Used for Shield Versioning bit value 4
    pinMode(verPIN3, INPUT);      //Used for Shield Versioning bit value 4
    pinMode(testPIN, OUTPUT);
  #endif
  //boardVersion();               //Use the function here during production
}

void loop() {
  boardVersion();                 //Placing function here enables testing
  Serial.println(shieldVersion);
  delay(1000);
}

void boardVersion() {
  #ifdef MEGABoard
    digitalWrite(testPIN, HIGH);
    delay(10);
    shieldVersion = digitalRead(verPIN0) | (digitalRead(verPIN1) << 1) | (digitalRead(verPIN2) << 2) | (digitalRead(verPIN3) << 3);
    digitalWrite(testPIN, LOW);
  #else
    shieldVersion = 0;
  #endif
}