I'm completely new to the Arduino community, so I only know the few basics!
I'm trying to make a pan/tilt system for a camera jib/crane using an Uno board, with this motor controller: http://www.amazon.co.uk/Big-Bargain-Stepper-Controller-Arduino/dp/B00AAYOIEK/ref=reg_hu-rd_add_1_dp and 2x Geared DC Motors (6V, 20RPM) which obviously I have to power separately from the Arduino Uno board.
What I'm trying to achieve is to be able to control the speed and direction each motor shaft with a joystick/thumbstick (the Xbox 360 styled ones), possibly with another potentiometer somewhere to control the speed even further. It's pretty much the same as David Holmes on Youtube is doing - YouTube here.
My Arduino Uno came in the post today so I've been programming for the past few hours. I think I'm on the right track with the following code:
int pan = 3;
int tilt = 5;
int VRpan = A0;
int VRtilt = A1;
int panval = 0;
int tiltval = 0;
void setup()
{
Serial.begin(9600);
pinMode(pan, OUTPUT);
pinMode(tilt, OUTPUT);
pinMode(VRpan, INPUT);
pinMode(VRtilt, INPUT);
}
void loop()
{
panval = analogRead(VRpan);
tiltval = analogRead(VRtilt);
if(panval < 502) //for the pan motor
{
//Rotate Clockwise
}
else if(panval > 522)
{
//Rotate Counterclockwise
}
else
{
//Release
}
if(tiltval < 502)
{
//Rotate Clockwise
}
else if(tiltval > 522)
{
//Rotate Counterclockwise
}
else
{
//Release
}
}
Basically, I want to know if the code looks okay so far, so that I know I'm on the right track! (again, I'm new to Arduino, I don't know much about the code!)
I'm putting the X axis of the thumbstick potentiometer as an input to analog pin 0, and the Y axis of the thumstick/pot as an input to analog pin 1.
When the thumbstick is centred, I don't want either motor shaft to rotate, and instead be released (Is that right?). So I understand I need to set a 'deadzone' which I have done from 502-522 values that are read from the joystick pot.
Next, I've used If statements. Is this the way that I should be doing it? If not, please correct me! As you can see, I need to do a bit of research for the code that enables the PWM to the motor controller. I'm just curious as to how it communicates with it so that the motor rotates either Clockwise or counterclockwise, and I take it the variable speed is done by PWM?
Any help would be appreciated! Thanks.
James