Advertisement
Shanmhel

Dec/Inc Pendulum by Sean

Apr 30th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /*
  2. Dec/Inc Pendulum Sweep by Sean
  3. */
  4.  
  5. #include <VarSpeedServo.h>
  6.  
  7. VarSpeedServo myservo; // create servo object to control a servo
  8. // a maximum of eight servo objects can be created
  9.  
  10. const int servoPin = 9; // the digital pin used for the servo
  11.  
  12. int val1=0; // variable to read the value from the analog pin
  13. int val2=180; // variable to read the value from the analog pin
  14. int x;
  15.  
  16.  
  17. void setup() {
  18. myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
  19. //myservo.write(90,80,true); // set the intial position of the servo, as fast as possible, wait until done
  20. Serial.begin(9600);
  21.  
  22. }
  23.  
  24. void loop() {
  25. for (int x=0; x<180; x+=2) {
  26. val1 +=2;
  27. myservo.write(val1,80,true); // you can adjust the 80 speed
  28. Serial.println ("val1=");
  29. Serial.println (val1);
  30. myservo.write(val2,80,true); // you can adjust the 80 speed
  31. val2 -=2;
  32. Serial.println ("val2=");
  33. Serial.println (val2);
  34.  
  35. Serial.println ("val1=");
  36. Serial.println (val1);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement