Hi
I recently purchased an Arduino Uno R3 board with a Arduino Motor Shield Rev3 as well as a joystick breakout board. My aim is to use the thumb joystick to control the direction of the stepper motor on the X-axis, left to right as well as the speed. So far I've been looking for good tutorials on the net with regards to the subject but had no luck so far.
Attached to this article are two photos showing how I connected my joystick to the motor shield board as well as a closeup view of the specific joystick I bought. Here is a link to the joystick as well:
Below is some sample code I downloaded from the net which rotates the shaft from one direction to the other with a delay. How can I modify this code to work with my setup and control the motor via the joystick:
#include <Stepper.h>
const int spr = 200; // motor steps per revolution
const int pwm_cha = 3;
const int pwm_chb = 11;
const int dir_cha = 12;
const int dir_chb = 13;
const int brake_cha = 9;
const int brake_chb = 8;
Stepper stepper(spr, dir_cha, dir_chb);
void setup()
{
pinMode(pwm_cha, OUTPUT);
pinMode(pwm_chb, OUTPUT);
pinMode(brake_cha, OUTPUT);
pinMode(brake_chb, OUTPUT);
digitalWrite(pwm_cha, HIGH);
digitalWrite(pwm_chb, HIGH);
digitalWrite(brake_cha, LOW);
digitalWrite(brake_chb, LOW);
stepper.setSpeed(75);
}
void loop()
{
stepper.step(spr);
delay(0);
stepper.step(-spr);
delay(0);
}
Any help would really be appreciated!
Regards