Advertisement
Guest User

Untitled

a guest
May 29th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo Motor[2];
  3.  
  4. int sensorPins[]={A0,A1};
  5. int sensorValues[] = {0, 0};
  6. int motorTurn[] = {0, 0};
  7. int echoPin= 12;
  8. int trigPin = 11;
  9. long duration ;
  10.  
  11. long distance;
  12.  
  13.  
  14. void setup() {
  15. // put your setup code here, to run once:
  16. Motor[0].attach(9);
  17.  
  18.  
  19. Motor[1].attach(13);
  20. Serial.begin(9600);
  21. pinMode(trigPin, OUTPUT);
  22. pinMode(echoPin, INPUT);
  23. }
  24.  
  25. void loop() {
  26. digitalWrite(trigPin,LOW);
  27. delayMicroseconds(2);
  28. digitalWrite(trigPin,HIGH);
  29. delayMicroseconds(10);
  30. digitalWrite(trigPin,LOW);
  31. duration= pulseIn(echoPin ,HIGH);
  32. distance=duration/29.1;
  33. Serial.println(distance);
  34.  
  35. motorTurn[0] = map(distance, 0, 200, 0, 150);
  36. motorTurn[1] = map(distance, 0, 200, 0, 150);
  37. Motor[0].write(motorTurn[0]);
  38. Motor[1].write(motorTurn[1]);
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement