Snippets

Dr Wolf servo arduino

Created by Andrea Agili last modified
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
Servo myservo1;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int minValue = 0;
int maxValue = 180;
int ms = 15;
int runs = 0;

void setup() {
  Serial.begin(9600);
  myservo.attach(4);  
  myservo1.attach(3);
}

void loop() {
  if (runs<1){
    Serial.println("loop");
    Serial.println(runs);
    for (pos = minValue; pos <= maxValue; pos += 1) { // goes from 0 degrees to 180 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      myservo1.write(maxValue-pos);              // tell servo to go to position in variable 'pos'
      delay(ms);                       // waits 15ms for the servo to reach the position
    }
    for (pos = maxValue; pos >= minValue; pos -= 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);  
      myservo1.write(maxValue-pos);  
      delay(ms);                       // waits 15ms for the servo to reach the position
    }
    runs++;
  }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.