Help me please to control my servo spin.

Hello, I am using a servo motor to control the rotation of my object. I know that the code for the motor to spin automatically is the following: #include <Servo.h>

Servo servowrist;

void setup() {
// put your setup code here, to run once:
servowrist.attach(7);
}

void loop() { // Loop through motion tests
alltovirtual(); // Example: alltovirtual
delay(4000); // Wait 4000 milliseconds (4 seconds)
alltorest(); // Uncomment to use this
delay(4000); // Uncomment to use this

alltomax(); // Uncomment to use this
delay(2000);
}

void alltovirtual() {
servowrist.write(0);
}

void alltorest() {
servowrist.write(0);
}
void alltomax() {
servowrist.write(180);
}

I found that there is a code that you can use a Potentiometer to control the servo here: http://www.instructables.com/id/ArduinoServoPotentiometer. However, I want to somehow try and make the user input the angle into the arduino code and then the arduino will spin it at the angle. Is that possible or would that have to involve some outside coding such as Python or C++?

Moderator edit: Fixed thread title.

If you have a continuous rotation servo you cannot make it go to a specific angle. You can only control its speed and direction.

I suspect for your potentiometer control to be useful/useable you will need to remove ALL the delay()s and use millis() to manage timing as illustrated in several things at a time

There is code to manage a servo with a potentiometer in planning and implementing a program.

...R

One way is to make a small console app in C++ yes.

cin is easy enough but it's getting that data to the arduino that is a snip more challenging - 2 steps involved:

Getting serial comms to the arduino going.

Then, as servo.writeMicroseconds(uS) has more resolution than 256 steps (1byte), you're going to have to make up your own comms protocol to relay the data you're interested in - pretty much bitwise operations.

It's kind of 4 steps as each of these need to be done at each end. An LCD helps no end in debugging :drooling_face:

Still keen?

You could use an LCD and a numeric keyboard also - then it's arduino only ...