I just got in the sparkfun joystick retail for a couple dollars of of sparkfun.
https://www.sparkfun.com/tutorials/272
The instructions only tell me how to make the serial monitor print the position of the joystick. But, i want to figure out how to control a servo with it.
I have this up online but the results i come up with are for a different kind of joystick and i can't figure out the right connections
If you can figure it out thank you in advance
zoomkat
February 28, 2014, 1:00am
#2
Below is some servo/pot test code you can try (a joystick has two pots).
//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor
#include <Servo.h>
Servo myservoS1;
Servo myservoS2;
int potpinS1 = 0; //analog input pin A0
int potpinS2 = 1;
int newvalS1, oldvalS1;
int newvalS2, oldvalS2;
void setup()
{
Serial.begin(9600);
myservoS1.attach(2);
myservoS2.attach(3);
Serial.println("testing dual pot servo");
}
void loop()
{
newvalS1 = analogRead(potpinS1);
newvalS1 = map(newvalS1, 0, 1023, 0, 179);
if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){
myservoS1.write(newvalS1);
Serial.print("1- ");
Serial.println(newvalS1);
oldvalS1=newvalS1;
}
newvalS2 = analogRead(potpinS2);
newvalS2 = map(newvalS2, 0, 1023, 0, 179);
if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){
myservoS2.write(newvalS2);
Serial.print("2- ");
Serial.println(newvalS2);
oldvalS2=newvalS2;
}
delay(50); //slow down looping to better read serial monitor
}