Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Sweep
  2.   by BARRAGAN <http://barraganstudio.com>
  3.   This example code is in the public domain.
  4.  
  5.   modified 28 May 2015
  6.   by Michael C. Miller
  7.   modified 8 Nov 2013
  8.   by Scott Fitzgerald
  9.  
  10.   // use Vin and GND
  11.   use pins D7, GND and 5V
  12.  
  13.   http://arduino.cc/en/Tutorial/Sweep
  14. */
  15.  
  16. #include <Servo.h>
  17.  
  18. Servo myservo;  // create servo object to control a servo
  19.  
  20.  
  21. void setup() {
  22.   Serial.begin(115200);
  23.   // d7 on the wemos D1
  24.   // attaches the servo on GIO2 to the servo object
  25.   myservo.attach(13);  
  26. }
  27.  
  28. void loop() {
  29.   int pos;
  30.   int startPosition = -10;
  31.   int endPosition = 80;
  32.   int millisecondStep = 10;
  33.  
  34.   for (pos = startPosition; pos <= endPosition; pos += 1) { // goes from 0 degrees to 180 degrees
  35.     // in steps of 1 degree
  36.     Serial.print(pos);
  37.     Serial.print("\n");
  38.     myservo.write(pos);              
  39.     delay(millisecondStep);                      
  40.   }
  41.   for (pos = endPosition; pos >= -startPosition; pos -= 1) {
  42.     myservo.write(pos);  
  43.     delay(millisecondStep);                      
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement