Created
May 9, 2019 21:06
-
-
Save Jatin1o1/cd5f21d4f511117652c95dae9d549fb4 to your computer and use it in GitHub Desktop.
servo sweep for specific time duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo myservo; | |
int pos = 0; | |
void setup() { | |
myservo.attach(9); | |
Serial.begin(9600); | |
} | |
int jatin=2000; // interval for which servo will sweep | |
unsigned long cm; // current miliseconds | |
void loop() { | |
myservo.write(0); // setting servo pos at default | |
cm=millis(); // starting measuring miliseconds | |
if(cm<jatin) // comparing elapsed miliseconds to interval | |
{ | |
// servo sweep program start | |
for (pos = 0; pos <= 30; pos += 10) { | |
myservo.write(pos); | |
delay(15); | |
} | |
for (pos = 30; pos >= 0; pos -= 10) { | |
myservo.write(pos); | |
delay(15); | |
} // servo sweep program ends | |
Serial.println(cm); // println elapsed miliseconds | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment