So, Hi Guys.
I am new with Arduino and i want to build a Joystick Stepmotor control. I found a Code in Internet and tryed to change it for my project. But when the sketch is running my Step Motor turns at the start, but i want that it stops when the Joystick is by 470-550 and goes forward by >550 and backward by <470.
I will be very thankful for your Help.
Here is the Sketch;
#include <Stepper.h>
const int num_step = 200;
const int pulPin = 8;
const int dirPin = 9;
const int enblPin = 10;
int loops = 0;
int Pot1 = 0;
int val;
Stepper stepper(num_step, dirPin, pulPin);
void setup() {
Serial.begin(9600);
pinMode(pulPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enblPin, OUTPUT);
digitalWrite(pulPin, LOW);
digitalWrite(dirPin, LOW);
digitalWrite(enblPin, LOW);
digitalWrite(enblPin, HIGH);
delay(100);
digitalWrite(enblPin, LOW);
}
void loop() {
int PVal=analogRead(Pot1);
if (PVal >= 470 || PVal <= 550)
{
// which command do i need here???
}
if (PVal > 550 )
{
int K= map (PVal, 551,1023,0,400); /* max is the value that you get from your experiment with the max speed of the stepper before stalling*/
int S=map (K, 0,400,0,num_step);
stepper.setSpeed(K); //this set the speed of the stepper motor
stepper.step(S); //this set the direction and the number of step it would take
Serial.print(“Forward, K=”);
Serial.print(K);
Serial.print(" PVAL=");
Serial.println(PVal);
}
if (PVal < 470 )
{
int K= map (PVal, 0,469,400,0); /* max is the value that you get from your experiment with the max speed of the stepper before stalling*/
int S=map (K, 0,400,0,num_step);
stepper.setSpeed(K); //this set the speed of the stepper motor
stepper.step(-S); //this set the direction and the number of step it would take
Serial.print(“Backward, K=”);
Serial.print(K);
Serial.print(" PVAL=");
Serial.println(PVal);
}
}