Hello and thanks for your replys. I really appreciate it.
If your not familar with the Adafruit Motorshield i have its this one:
It has no importance for me to use this shield i just saw it as an
easy way to achieve my goal with this project: to start filming ![]()
So if anyone have another entry to this project or a good
tutorial somewhere please let med know.
I tried to rename the 2 analog pins with an X and Y in the end
and it solved the issue with the error compiling the code.
But the 2 stepper motors act strange - they both move
when i move the joystick X or Y-axis, and i got a humbling
sound from both motors when the power is on.
and they do not really react very well - it's actually better
if i just connect one motor and a potentiometer.
I have tried to make the schematic in fritzing, but they
didn't have the Ada motorshield, so i had to impovise
in Photoshop with the original print - i moved it a bit,
so its possible to see the number of the pins the shield use.
The code as it is on the Arduino now:
#include <Stepper.h>
#include <AccelStepper.h>
#include <AFMotor.h>
AF_Stepper motor1(225, 1);
AF_Stepper motor2(225, 2);
int analogPinX = A0; // X potentiometer wiper (middle terminal)
int analogPinY = 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(analogPinX); // read the input pins
val = analogRead(analogPinY); // read the input pins
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);
}
}
}
Thanks for looking at this.
/Jakob
