#include Servo myservo; int distance; int pos=0; void setup() { pinMode(13,OUTPUT); pinMode(12,INPUT); pinMode(11,OUTPUT); myservo.attach(10); Serial.begin(9600); } void loop() { digitalWrite(13,1); delayMicroseconds(10); digitalWrite(13,0); distance = pulseIn(12,HIGH)/58.2; Serial.println(distance); if(distance <=90){ digitalWrite(11,1); delay (3000); myservo.write(0); delay(300); myservo.write(45); delay(300); myservo.write(90); delay(300); myservo.write(135); delay(300); myservo.write(180); myservo.write(180); delay(300); myservo.write(135); delay(300); myservo.write(90); delay(300); myservo.write(45); delay(300); myservo.write(0); delay(300); } else { digitalWrite(11,0); } }
|