#include<Servo.h>Servomyservo;// create servo object to control a servoServomyservo1;// create servo object to control a servo// twelve servo objects can be created on most boardsintpos=0;// variable to store the servo positionintminValue=0;intmaxValue=180;intms=15;intruns=0;voidsetup(){Serial.begin(9600);myservo.attach(4);myservo1.attach(3);}voidloop(){if(runs<1){Serial.println("loop");Serial.println(runs);for(pos=minValue;pos<=maxValue;pos+=1){// goes from 0 degrees to 180 degreesmyservo.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 degreesmyservo.write(pos);myservo1.write(maxValue-pos);delay(ms);// waits 15ms for the servo to reach the position}runs++;}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.