Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myservo;
  3. int pos = 0;
  4.  
  5. void setup() {
  6.  
  7. Serial.begin(9600);
  8. myservo.attach(9);
  9.  
  10. }
  11.  
  12.  
  13. void loop() {
  14.  
  15. int sensor1 = analogRead(A0);
  16. Serial.print("1:");
  17. Serial.println(sensor1);
  18. int sensor2 = analogRead(A1);
  19. Serial.print("2:");
  20. Serial.println(sensor2);
  21. pos= myservo.read();
  22. if (sensor1>200 || sensor2>200)
  23. {
  24. if (abs(sensor1-sensor2)<=3)
  25. {
  26. goto next;
  27. }
  28. if (sensor1 > sensor2)
  29. {
  30. myservo.write(pos+3);
  31. }
  32. if (sensor1 < sensor2)
  33. {
  34. myservo.write(pos-3);
  35. }
  36. }
  37. next:
  38. delay(300);
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement