daily pastebin goal
49%
SHARE
TWEET

FSE

a guest Jan 22nd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. #define echoPin 7 // Echo Pin
  3. #define trigPin 8 // Trigger Pin
  4. #define Pizo 12 //The Pizo
  5. Servo ServoRight;
  6. Servo ServoLeft;
  7. int xVal ;
  8. int yVal;
  9. int servoRight;
  10. int servoLeft;
  11. int maximumRange = 300;
  12. int minimumRange = 10;
  13. long duration, distance;
  14. const int light = 5;
  15. const int light1 = 6;
  16. boolean x = true;
  17.  
  18. void setup() {
  19.  
  20. Serial.begin(9600);
  21. ServoRight.attach(6);
  22. ServoLeft.attach(5);
  23. pinMode(trigPin, OUTPUT);
  24. pinMode(echoPin, INPUT);
  25. pinMode(Pizo, OUTPUT);
  26. pinMode(light , OUTPUT);
  27. pinMode(light1 , OUTPUT);
  28. }
  29. void loop(){
  30. xVal = analogRead(A0);
  31. yVal = analogRead(A1);
  32. Serial.print("X= ");
  33. Serial.println (xVal);
  34. Serial.print("Y= ");
  35. Serial.println(yVal);
  36.  
  37.  
  38. if (yVal < 400)
  39. {
  40. ServoRight.write(180);
  41. ServoLeft.write(0);
  42. }
  43. else if (yVal > 600)
  44. {
  45.   ServoRight.write(0);
  46.   ServoLeft.write(180);
  47.   }
  48.  
  49.  
  50. else if (xVal < 400)
  51. {
  52.  ServoRight.write(180);
  53.  ServoLeft.write(180);
  54.  digitalWrite(13, HIGH);
  55.  
  56.  }
  57. else if (xVal > 600)
  58. {
  59.  ServoRight.write(0);
  60.  ServoLeft.write(0);
  61.  digitalWrite(12, HIGH);
  62.  }
  63.  else  (yVal, xVal = 509, 510, 511, 512, 513);
  64. {
  65. ServoRight.write(90);
  66. ServoLeft.write(90);
  67.   }
  68.  
  69.      digitalWrite(trigPin, LOW);
  70.     delayMicroseconds(2);
  71.  
  72.     digitalWrite(trigPin, HIGH);
  73.     delayMicroseconds(10);
  74.  
  75.     digitalWrite(trigPin, LOW);
  76.     duration = pulseIn(echoPin, HIGH);
  77.  
  78.     distance = duration/58.2;
  79.  
  80.     if (distance >= maximumRange || distance <= minimumRange) {
  81.         Serial.println("Good thing yall aint testing me today would've ran your a** over");
  82.        
  83.     } else {
  84.         Serial.println("BOY IF YOU DONT MOVE IM FINNA RUN YOU OVER STOOOOOOOOPED");
  85.          Serial.print(distance);
  86.     Serial.println(" cm");
  87.     }
  88.     int thisPitch = map(distance, 0, 200, 2093, 22);
  89.   tone(4, thisPitch);
  90.   delay(500);
  91.   noTone(4);
  92.  
  93. delay(10);
  94.  
  95. int c = analogRead(A2);
  96.   delay(500);
  97. if ( c<300 && x == true){
  98.   digitalWrite(5, HIGH);
  99.    x = false;
  100.    digitalWrite(6, HIGH);
  101.    x = false;
  102.    delay(1000);
  103.  
  104. }
  105. else if ( c <300 && x == false){
  106. x = true;
  107. digitalWrite(5,LOW);
  108. digitalWrite(6,LOW);
  109. delay(1000);
  110. }
  111. }
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