Here is the code that I am currently working on
//Assigning joystick shield pin
int speed_Y = 0;
int joystickValue_Y = 0;
int centerYValue = 0;
const int Y_THRESHHOLD_LOW = 500;
const int Y_THRESHHOLD_HIGH = 510;
//Assigning Joystick Shield pins
int pinStickY = 1;
//Assigning Easydriver
int pinSTEP = 13; // Step
int pinDIR = 12; // Direction
int pinMS1 = 11; // MicroStep 1
int pinSLP = 10; // Sleep
int pinMS2 = 9; // MicroStep 2
int pinENA = 8; // Enable
void setup() {
pinMode(pinSTEP, OUTPUT);
pinMode(pinDIR, OUTPUT);
pinMode(pinENA, OUTPUT);
}
void loop() {
joystickValue_Y = analogRead(pinStickY); //Reads number for joystick in Y-Dir
centerYValue = joystickValue_Y - 516; //516 is the center position of MY joystiuck shield
centerYValue = abs(centerYValue);//If negative, turns nonnegative
speed_Y = 1000/centerYValue; //Inverts the value and scales as needed. Change the value as needed!!!! The delay between steps determines the speed of the motor, delay up = speed down.
if (joystickValue_Y > Y_THRESHHOLD_HIGH){
digitalWrite(pinENA, LOW); //Enable
digitalWrite(pinDIR, HIGH); //Set Direction
digitalWrite(pinSTEP, HIGH);
delayMicroseconds(2);
digitalWrite(pinSTEP, LOW);
delayMicroseconds(speed_Y);
}
if (joystickValue_Y < Y_THRESHHOLD_LOW) {
digitalWrite(pinENA,LOW);// enable
digitalWrite(pinDIR, LOW); // Other direction
digitalWrite(pinSTEP,HIGH);
delayMicroseconds(2);
digitalWrite(pinSTEP,LOW);
delayMicroseconds(speed_Y);
}
if (joystickValue_Y <=Y_THRESHHOLD_HIGH && joystickValue_Y >= Y_THRESHHOLD_LOW) {
digitalWrite(pinENA,HIGH); // disable the stepper motor if the joystick is in the center
}
}
I am using an Arduino UNO board with a Sparkfun Joystick Shield connected to a Easy driver board which is going to the bipolar motor.
here is my problem, whenever I press the joystick forward or pull it back the motor only turns counterclockwise. I have tried changing pinDIR from HIGH to LOW and reverse but I am new to this programming. Wanted to understand how to do it myself before I start using libraries.