Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement