I have an issue with 360 degree servo. when I pressed the button on my thumbstick shield I want the 360 degree servo to come back its origin point. as you might know center point is set by a screw on the servo. I found this code and it works perfectly but it doesnt include a button function. I appreciate for any help.
int t = 10;
Servo SR04; // Full rotational
int PinReading = 0;
int potentiometer = 0;
// put your setup code here, to run once:
SR04.attach(9);// servo connected to D9
// put your main code here, to run repeatedly:
PinReading = analogRead(A0);
potentiometer = map(PinReading, 0, 1023, 0, 180);
potentiometer = constrain(potentiometer, 0, 180);
Most, if not all, 360° servos are continuous rotation, not limited to just 360° of travel. (Mine are.) Does your servo spin continuously in one direction when you write a value >90, spin continuously in the other direction when you write a value <90, and stop turning when you write 90 to it?
If so, there is no centre point. 90 would be the centre point on a std servo, but it’s just ‘stop’ on a CR servo, so you won’t be able to do what you want. 90 is ‘stop’ as mentioned, and values further above and below 90 just increase the speed in each direction.
On a CR servo, the trim screw is used to trim the servo so that it stays still at 90.
And another point, when posting code on these forums, you’re expected to place it between code tags, “</>” at the top-left corner of the ‘Post’ window.
It should also be formatted correctly, with indentations where necessary. The best/easiest way to format it is to click on >Tools >Auto Format before copying and pasting into your post. Note how I’ve done it in the quote above.
These steps make code much more readable for people who might want to help you, and also allows them to easily copy the code for testing in their IDE.