Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. int sensorPin = A0;
  4. int servoPin = 9;
  5.  
  6. int sensorValue = 0;
  7. int servoGrad = 90;
  8. int tolerance = 40;
  9.  
  10. Servo myservo;
  11.  
  12. void setup() {
  13. pinMode( sensorPin, INPUT);
  14. myservo.attach( servoPin );
  15. myservo.write( servoGrad );
  16. }
  17.  
  18. void loop() {
  19. sensorValue = analogRead(sensorPin);
  20. if ( sensorValue < (512-tolerance) )
  21. {
  22. if (servoGrad < 180) servoGrad++;
  23. }
  24.  
  25. if ( sensorValue > (512+tolerance) )
  26. {
  27. if (servoGrad > 0) servoGrad--;
  28. }
  29.  
  30. myservo.write( servoGrad );
  31.  
  32. delay(100);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement