Hello someone give me some help og maybe a hint??
Thanks in advance.
I'm very-very new to Arduino, and have folloved the basic
setups to get familiar with the hardware ande code.
I am working on a pan-tilt head for my DSlR camera.
I will use 2 stepper motors for this project.
My goal is to control x+y axis with a simple
Thumbstick (joystick) (like the one used in a xbox360 contr.)
I have a Arduino Mega 1280 + Adafruit Motorshield
I have managed to make one of the steppers work quite well
with just connecting a potentiometer to Analog pin 0,
but i simply can't make it work with 2 steppers - i have read the
explanation from Adafruit many times and a lot more tutorials
on the net, but i didn't find anyone with the setup i have.
I am working with this code, but i get some erros when i try to compile
the code in Arduino software.
Code:
#include <Stepper.h>
#include <AccelStepper.h>
#include <AFMotor.h>
AF_Stepper motor1(225, 1);
AF_Stepper motor2(225, 2);
int analogPin = A0; // X potentiometer wiper (middle terminal)
int analogPin = A5; // Y potentiometer wiper (middle terminal)
//connected to analog pin 0 and 5
// outside leads to ground and +5V
int val = 0; // Pot1 variable to store the value read
int prepos = 0;
int pos = 0; //0 to 224 .
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
motor1.setSpeed(60); // 30 rpm
motor2.setSpeed(60); // 30 rpm
}
void loop() {
prepos = pos;
val = analogRead(analogPin); // read the input pins
pos = map (val, 0, 1024, 0, 224);
pos = map (val, 0, 1024, 0, 224);
if (pos != prepos){
int diststep = pos - prepos;
if (diststep < 0) {
motor1.step(-diststep, BACKWARD, INTERLEAVE);
motor2.step(-diststep, BACKWARD, INTERLEAVE);
}
if (diststep > 0) {
motor1.step(diststep, FORWARD, INTERLEAVE);
motor2.step(diststep, FORWARD, INTERLEAVE);
}
}
}
