Advertisement
Guest User

Untitled

a guest
May 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myservo;
  3. int pos = 0;
  4.  
  5. void setup() {
  6. myservo.attach(9);
  7. Serial.begin(9600);
  8.  
  9. }
  10. int jatin=2000; // interval for which servo will sweep
  11. unsigned long cm; // current miliseconds
  12. void loop() {
  13. myservo.write(0); // setting servo pos at default
  14. cm=millis(); // starting measuring miliseconds
  15. if(cm<jatin) // comparing elapsed miliseconds to interval
  16. {
  17. // servo sweep program start
  18. for (pos = 0; pos <= 30; pos += 10) {
  19. myservo.write(pos);
  20. delay(15);
  21. }
  22. for (pos = 30; pos >= 0; pos -= 10) {
  23. myservo.write(pos);
  24. delay(15);
  25. } // servo sweep program ends
  26. Serial.println(cm); // println elapsed miliseconds
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement