Last active
March 22, 2024 13:12
-
-
Save Swap-File/f77639f6d774324f3b17462b9ce35999 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
#define DELAY_TIME_MS 30 | |
void setup() { | |
myservo.attach(9); | |
} | |
void loop() { | |
myservo.attach(9); | |
for (pos = 1; pos <= 179; pos += 1) { // goes from 1 degrees to 179 degrees (don't go all the way from 0 to 180 on cheap servos) | |
// in steps of 1 degree | |
myservo.write(pos); // tell servo to go to position in variable 'pos' | |
delay(DELAY_TIME_MS); | |
} | |
myservo.detach(); //detatch to prevent vibration on cheap servos during delay | |
delay(DELAY_TIME_MS * 180); | |
myservo.attach(9); | |
for (pos = 179; pos >= 1; pos -= 1) { // goes from 179 degrees to 1 degrees (don't go all the way from 0 to 180 on cheap servos) | |
myservo.write(pos); // tell servo to go to position in variable 'pos' | |
delay(DELAY_TIME_MS); | |
} | |
myservo.detach(); //detatch to prevent vibration on cheap servos during delay | |
delay(DELAY_TIME_MS * 180); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment