SHARE
TWEET

Programming the Servo Motor to Change Direction

jmyean Apr 21st, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. /* Jung Min Yean
  4.  *  Using the Servo Motor
  5.  *  Using the for loop
  6.  *  04/16/19
  7.  */
  8.  
  9. #include <Servo.h> // the servo library (every time this is included, you must add an object
  10.  const int servoPin = 3;
  11.  Servo myservito;
  12.  
  13.  void setup()
  14. {
  15.   myservito.attach(servoPin);
  16.   Serial.begin(9600);
  17. }
  18.  
  19. void loop()
  20. {
  21.   for(int i = 0; i < 180; i++) // loop from 0 - 180
  22.   { myservito.write(i);
  23.   delay(10);
  24.   }
  25.  
  26.   for(int i = 180; i > 0; i--) // loop from 180 - 0
  27.   { myservito.write(i);
  28.   delay(10);
  29.   }
  30.  
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top