blob: b9f10360d6fd55ad859f4c7d87644b152ff73ab9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 2; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int i;
void setup(){
myservo.attach(9); // attach the servo object on to pin 9
for(i=0;i<5000;++i){
val = analogRead(potpin); // reads a value in (0,1023) through pot
val = map(val, 0, 1023, 0, 180); // maps it in the range (0,180) degrees
myservo.write(val); // moves the motor to the mapped degree
delay(500); // waits for a second for servo to reach
}
myservo.detach();
}
void loop(){
}
|