Hi All,
I'm trying to control a stepper with a mini joystick via Adafruit motor sheld v2.3 on my Arduino uno.
I want it to stop/not turn when the joystick is centred and accelerate between 0-50rpm in ether direction the further across the joystick is moved. Hopefully that's clear as mud.
The code I have is spiced and hacked along with my joystick. My joystick only reads about +/-13 from 512, not sure why, it's out of an old ps3 controller.
My end goal is to control multiple steppers, dc motors and servos with joysticks and buttons but these steppers are proving to be more difficult than the others.
I managed to get this to compile after many many hours working at it but alas it doesn't run the stepper. Can anyone help me with it please?
#include <Stepper.h>
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(48, 2);
int num_step = 48;
int val();
int joystick = A1;
void setup()
{
myMotor->setSpeed(0);
}
void loop()
{
int val=analogRead(joystick);
if (val >= 509 || val <= 515)
if (val > 515 )
{
int K= map (val, 515,527,0,50);
int S=map (K, 0,50,0,num_step);
myMotor->setSpeed(K); //this set the speed of the stepper motor
myMotor->step(S, MICROSTEP); //this set the direction and the number of step it would take
}
if (val < 509 )
{
int K= map (val, 498,508,0,50);
int S=map (K, 0,50,0,num_step);
myMotor->setSpeed(K); //this set the speed of the stepper motor
myMotor->step(-S, MICROSTEP); //this set the direction and the number of step it would take
}
}