Hi everybody!
(First of all, excuse my English)
Today I've been trying to program a Servo in many ways but there's one I don't know how to.
What I want to do is to change the spinning speed of the servo. For that purpose I've writen this:
(Notes:
posicion --> position
velocidad --> velocity
vel0 --> initial velocity
pot --> pot. value
#include <Servo.h>
Servo servo;
int posicion;
int velocidad;
int pot;
void setup() {
servo.write(90);
posicion = 90;
servo.attach(3);
pinMode(A0, INPUT);
}
void loop() {
pot = analogRead(A0);
velocidad = map(pot, 0, 1023, -90, 90);
for(velocidad > 0; posicion < 180; posicion++){
int vel0 = velocidad;
servo.write(posicion);
delay(500/velocidad);
if(velocidad != vel0){
break;
velocidad = map(pot, 0, 1023, -90, 90);
}
}
for(velocidad < 0; posicion > 0; posicion--){
int vel0 = velocidad;
posicion--;
servo.write(posicion);
delay(500/velocidad);
if(velocidad != vel0){
break;
velocidad = map(pot, 0, 1023, -90, 90);
}
}
servo.write(posicion);
}
What I expected to do with thos code was to be abble to know the position of the servo in any moment so I could work with the range of positions [0-180].
It doesn't work now. If you could help me I would be so happy
Thank you!