/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo motor; // create servo object to control a servo
int botao = 7;
int val; // variable to read the value from the analog pin
int velocidade = 20;
void setup() {
motor.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(botao, INPUT_PULLUP);
}
void loop() {
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
motor.write(val); // sets the servo position according to the scaled value
if(digitalRead(botao)==LOW){
for(int k=0; k<=180; k--){
motor.write(k);
delay(velocidade);
}
for(int k=0; k<=180; k++){
motor.write(k);
delay(velocidade);
}
for(int k=0; k<=180; k--){
motor.write(k);
delay(velocidade);
}
}
}