#define S1 0
#define S2 1
#define S3 2
#define M1 8
bool S1x,S2x,S3x;
void setup() {
pinMode(S1, INPUT_PULLUP);
pinMode(S2, INPUT_PULLUP);
pinMode(S3, INPUT_PULLUP);
pinMode(M1, OUTPUT);
}
void loop() {
S1x = !digitalRead(S1);
S2x = !digitalRead(S2);
S3x = !digitalRead(S3);
if (S1x and S2x and S3x)
digitalWrite(M1, HIGH);
if (S2x and !S1x and !S3x)
digitalWrite(M1, LOW);
}