// This is a program for testing the various I/O Devices

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int trigPin = 13;
int echoPin = 12;
long distance;
long duration;
 
void setup() 
{
 servo1.attach(11); 
 servo2.attach(10); 
 servo3.attach(9); 
 servo4.attach(8); 
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);// put your setup code here, to run once:
}
 
void loop() {
  ultra();
  if(distance <= 100)
  {
   servo1.write(360);
   servo2.write(270);
   servo3.write(180);
   servo4.write(90);
  }
  else
  {
    servo1.write(0);
    servo2.write(90);
    servo3.write(45);
    servo4.write(180);
  }

}
 
void ultra(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;
  }