// Define the input pins for the selector switch
const int selectorPin1 = 2;
const int selectorPin2 = 3;
const int selectorPin3 = 4;
const int selectorPin4 = 5;
// Define the output pins for the switch
const int outputPin1 = 6;
const int outputPin2 = 7;
const int outputPin3 = 8;
const int outputPin4 = 9;
// Define the off switch pin
const int offSwitchPin = 10;
void setup() {
// Set the input pins as inputs
pinMode(selectorPin1, INPUT);
pinMode(selectorPin2, INPUT);
pinMode(selectorPin3, INPUT);
pinMode(selectorPin4, INPUT);
// Set the output pins as outputs
pinMode(outputPin1, OUTPUT);
pinMode(outputPin2, OUTPUT);
pinMode(outputPin3, OUTPUT);
pinMode(outputPin4, OUTPUT);
// Set the off switch pin as input
pinMode(offSwitchPin, INPUT);
}
void loop() {
// Read the state of the selector switch pins
int selectorState1 = digitalRead(selectorPin1);
int selectorState2 = digitalRead(selectorPin2);
int selectorState3 = digitalRead(selectorPin3);
int selectorState4 = digitalRead(selectorPin4);
// Read the state of the off switch pin
int offSwitchState = digitalRead(offSwitchPin);
// Determine which output pin to turn on based on the selector switch state
if (selectorState1 == HIGH ) {
digitalWrite(outputPin1, HIGH);
digitalWrite(outputPin2, LOW);
digitalWrite(outputPin3, LOW);
digitalWrite(outputPin4, LOW);
} else if (selectorState2 == HIGH ) {
digitalWrite(outputPin1, LOW);
digitalWrite(outputPin2, HIGH);
digitalWrite(outputPin3, LOW);
digitalWrite(outputPin4, LOW);
} else if (selectorState3 == HIGH ) {
digitalWrite(outputPin1, LOW);
digitalWrite(outputPin2, LOW);
digitalWrite(outputPin3, HIGH);
digitalWrite(outputPin4, LOW);
} else if (selectorState4 == HIGH ) {
digitalWrite(outputPin1, LOW);
digitalWrite(outputPin2, LOW);
digitalWrite(outputPin3, LOW);
digitalWrite(outputPin4, HIGH);
} else {
}
// Turn off all output pins if the off switch is pressed
if (offSwitchState == HIGH) {
digitalWrite(outputPin1, LOW);
digitalWrite(outputPin2, LOW);
digitalWrite(outputPin3, LOW);
digitalWrite(outputPin4, LOW);
}
}