daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. Servo VerticalServo;
  3. Servo  GorizontalServo;
  4.  
  5. int echoPin = 2;
  6. int trigPin = 3;
  7.  
  8. #define ENA 4
  9. #define ENB 11
  10. #define IN1 7
  11. #define IN2 6
  12. #define IN3 5
  13. #define IN4 8
  14. #define RedIdeod 12
  15. void setup()
  16. {
  17.   VerticalServo.attach(10);
  18.   GorizontalServo.attach(9);
  19.   VerticalServo.write(108);
  20.  
  21.   Serial.begin (9600);
  22.   pinMode(trigPin, OUTPUT);
  23.   pinMode(echoPin, INPUT);
  24. }
  25.  
  26. void loop()
  27. {
  28.  
  29.   digitalWrite(IN1, HIGH);
  30.   digitalWrite(IN2, LOW);
  31.   analogWrite(ENA, 255);
  32.  
  33.   digitalWrite(IN3, HIGH);
  34.   digitalWrite(IN4, LOW);
  35.   analogWrite(ENB, 255);
  36.  
  37.   int leftDistance;
  38.   int rightDistance;
  39.   int duration, distation;
  40.  
  41.   digitalWrite(trigPin, LOW);
  42.   delayMicroseconds(2);
  43.   digitalWrite(trigPin, HIGH);
  44.   delayMicroseconds(10);
  45.   digitalWrite(trigPin, LOW);
  46.   duration = pulseIn(echoPin, HIGH);
  47.   distation = duration / 58;
  48.  
  49.   if (distation > 30) {
  50.     GorizontalServo.write(56);
  51.   }
  52.  
  53.  
  54.   if ((distation > 0) && (distation < 300)) {
  55.     Serial.print(distation);
  56.     Serial.println(" cm");
  57.     delay(100);
  58.   }
  59.   if (distation < 1) {
  60.     Serial.print("Робот выключен, пожалуйста нажмите на выключатель ");
  61.     Serial.println(" ");
  62.     delay(100);
  63.   }
  64.   if ((distation < 30) && (distation > 0 )) {
  65.     digitalWrite(IN1, LOW);
  66.     digitalWrite(IN2, LOW);
  67.     digitalWrite(IN3, LOW);
  68.     digitalWrite(IN4, LOW);
  69.  
  70.     GorizontalServo.write(7);
  71.  
  72.     digitalWrite(trigPin, LOW);
  73.     delayMicroseconds(2);
  74.     digitalWrite(trigPin, HIGH);
  75.     delayMicroseconds(10);
  76.     digitalWrite(trigPin, LOW);
  77.     rightDistance = pulseIn(echoPin, HIGH);
  78.     rightDistance = rightDistance / 58;
  79.     delay(1000);
  80.  
  81.     GorizontalServo.write(120);
  82.  
  83.     digitalWrite(trigPin, LOW);
  84.     delayMicroseconds(2);
  85.     digitalWrite(trigPin, HIGH);
  86.     delayMicroseconds(10);
  87.     digitalWrite(trigPin, LOW);
  88.     leftDistance = pulseIn(echoPin, HIGH);
  89.     leftDistance = leftDistance / 58;
  90.     delay(1000);
  91.  
  92.     GorizontalServo.write(55);
  93.     delay(1000);
  94.  
  95.     if (rightDistance > leftDistance) {
  96.       digitalWrite(IN1, HIGH);
  97.       digitalWrite(IN2, LOW);
  98.       digitalWrite(IN3, LOW);
  99.       digitalWrite(IN4, HIGH);
  100.       delay(380);
  101.     }
  102.  
  103.     if (rightDistance < leftDistance) {
  104.       digitalWrite(IN1, HIGH);
  105.       digitalWrite(IN2, LOW);
  106.       digitalWrite(IN3, LOW);
  107.       digitalWrite(IN4, HIGH);
  108.       delay(380);
  109.     }
  110.   }
  111.   if (distation == 0) {
  112.    analogWrite(12, 255);
  113.         delay(100);
  114.     if (rightDistance == 0) {
  115.      analogWrite(12, 255);
  116.         delay(100);
  117.       if (leftDistance == 0) {
  118.         analogWrite(RedIdeod, 255);
  119.         delay(100);
  120.       }
  121.     }
  122.   }
  123. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top