Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
1.0 kB
1
Indexable
Never
#include<Servo.h>
Servo s1,s2,s3,s4,s5,s6;
int trigPin = 3;
int echoPin = 2;

void setup(){
     s6.attach(4);
     s5.attach(5);
     s4.attach(6);
     s3.attach(7);
     s2.attach(8);
     s1.attach(9);
     pinMode(trigPin,OUTPUT);
     pinMode(echoPin, INPUT);
     Serial.begin(9600);
}
int dist(){
     int duration,distance;
     digitalWrite(trigPin,0);
     delayMicroseconds(2);
     digitalWrite(trigPin, 1);
     delayMicroseconds(10);
     digitalWrite(trigPin, 0);
     duration = pulseIn(echoPin, 1 , 10000);     
     distance = duration/58;
     return distance;
}
void config(int deg1, int deg2, int deg3, int deg4,int deg5,int deg6){
    s1.write(deg1);
    s2.write(deg2);
    s3.write(deg3);
    s4.write(deg4);
    s5.write(deg5);
    s6.write(deg6);
}

void loop()
{
     config(0,75,155,90,90,0);
     delay(1000/16);
     int i = 0;
     while(dist() > 20 || dist() == 0){

     Serial.println(dist());
     i +=5;
     s1.write(i);
     delay(500/16);
}
     delay(10000/16);

  


}
Leave a Comment