Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Adjusted from Sweep and Knob examples by Stijn van der Lippe
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- // twelve servo objects can be created on most boards
- int pos = 100; // variable to store the servo position, starts at 100 degrees
- int potpin = A0; // analog pin used to connect the potentiometer
- int wait; // variable to read the value from the analog pin
- void setup() {
- myservo.attach(9); // attaches the servo on pin 9 to the servo object
- }
- void loop() {
- wait = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
- wait = map(wait, 0, 1023, 150, 500);// scale it to use it with the delay (value between 150ms and 500ms)
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(wait); // waits a certain a amount of ms stored in variable 'wait' for the servo to reach the position
- pos += 80; // set position variable forward 80 degrees
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(wait); // waits a certain a amount of ms stored in variable 'wait' for the servo to reach the position
- pos -= 80; // set position variable back 80 degrees
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement