Hi,
I know that you can read a current angle of a servo motor using my_servo.read()
I wonder if it would be possible to:
- You turn the servo motor
- You read the new angle.
I did some test and you can't turn a servo while it's "attached". However even if you detached and turned the servo, the servo will come back to its place where it was left just before it was detached. I will give an example to make it clear.
The servo is attached and set to 0 degrees. You detach it(my_servo.detach()
) and turn it to 180 degrees. You reattach it(my_servo.attach(servo_pin)
) and hope that it will read 180 degrees. However what happens is that the servo turns to 0 degrees before anything happens, and then it will read 0 degree.
Here's the test code I wrote:
#include <Servo.h>
const int servo_pin = 6;
Servo servo;
void setup(){
Serial.begin(9600);
servo.attach(servo_pin);
servo.write(0);
}
void loop(){
Serial.print(servo.read());
Serial.print("\n");
servo.detach();
delay(4000);
servo.attach(servo_pin);
delay(1000);
}
So does anyone have any idea how I could read a manually set servo angle?
Thanks in advance