const int SW1 = 2;const int SW2 = 3;const int SW3 = 4; const int SW4 = 5;        
const int ledPin =  13;const int Relay1 =  12;const int Relay2 =  11;
const int Relay3 =  10; const int Relay4 =  9;     
int checkSW1 = 0;int checkSW2 = 0;int checkSW3 = 0;int checkSW4 = 0;
void setup() {
  //========กำหนด output================
  pinMode(ledPin, OUTPUT);
  pinMode(Relay1, OUTPUT); 
  pinMode(Relay2, OUTPUT);  
  pinMode(Relay3, OUTPUT); 
  pinMode(Relay4, OUTPUT);  
  //========กำหนด input==================
  pinMode(SW1, INPUT); 
  pinMode(SW2, INPUT);  
  pinMode(SW3, INPUT);  
  pinMode(SW4, INPUT);  
  //========กำหนดค่า output===================
  digitalWrite(Relay1, LOW); 
  digitalWrite(Relay2, LOW); 
  digitalWrite(Relay3, LOW); 
  digitalWrite(Relay4, LOW);  
}
void loop(){
  //============ตรวจสอบการควบคุม SW================
  checkSW1 = digitalRead(SW1);
  checkSW2 = digitalRead(SW2);
  checkSW3 = digitalRead(SW3);
  checkSW4 = digitalRead(SW4);
  //=============================================
  if (checkSW1 == LOW) {
    //UP();    
    digitalWrite(Relay1, HIGH);  
  } 
  if (checkSW2 == LOW) { 
    //DOWN();
    digitalWrite(Relay2, HIGH);  
  }
  if (checkSW3 == LOW) { 
    //RIGHT();    
    digitalWrite(Relay3, HIGH);  
  }
  if (checkSW4 == LOW) { 
    //LEFT();   
    digitalWrite(Relay4, HIGH);  
  }
  if (checkSW1 == HIGH && checkSW2 == HIGH && checkSW3 == HIGH && checkSW4 == HIGH) { 
    //STOP();    
    digitalWrite(Relay1, LOW); 
    digitalWrite(Relay2, LOW); 
    digitalWrite(Relay3, LOW); 
    digitalWrite(Relay4, LOW);   
  }
}
//=============function===================
void UP(){
//  Serial.print('RRR');
  digitalWrite(ledPin, HIGH);
  digitalWrite(Relay1,LOW);
  digitalWrite(Relay2,HIGH);
  digitalWrite(Relay3,LOW);
  digitalWrite(Relay4,HIGH);
}
void DOWN(){
//  Serial.print('RRR');
  digitalWrite(ledPin, HIGH);
  digitalWrite(Relay1,HIGH);
  digitalWrite(Relay2,LOW);
  digitalWrite(Relay3,HIGH);
  digitalWrite(Relay4,LOW);
}
void RIGHT(){
//  Serial.print('RRR');
  digitalWrite(ledPin, HIGH);
  digitalWrite(Relay1,HIGH);
  digitalWrite(Relay2,LOW);
  digitalWrite(Relay3,LOW);
  digitalWrite(Relay4,HIGH);
}
void LEFT(){
//  Serial.print('RRR');
  digitalWrite(ledPin, HIGH);
  digitalWrite(Relay1,LOW);
  digitalWrite(Relay2,HIGH);
  digitalWrite(Relay3,HIGH);
  digitalWrite(Relay4,LOW);
}
void STOP(){
//  Serial.print('RRR');
  digitalWrite(ledPin,LOW);
  digitalWrite(Relay1,LOW);
  digitalWrite(Relay2,LOW);
  digitalWrite(Relay3,LOW);
  digitalWrite(Relay4,LOW);
}


