The aim of this task is to control the direction of a stepper motor using a single press of a push switch. The rotational speed of the motor will be controlled by reading the values of a potentiometer. Reading the data from a push switch to perform a task for a single push (without holding the button down).
The rotational speed of the motor is defined by the delay value between the steps.
After reading the data from a potentiometer you can use the map function to modify the delay value (StepDelay) to control the rotational speed of the motor. This is the program so far but i am unsure where i have gone wrong, thanks!
int Stepper_IN1 = 10;
int Stepper_IN2 = 11;
int Stepepr_IN3 = 12;
int Stepper_IN4 = 13;
int StepDelay = 10;
void setup() {
pinMode (Stepper_IN1, OUTPUT);
pinMode (Stepper_IN2, OUTPUT);
pinMode (Stepper_IN3, OUTPUT);
pinMode (Stepper_IN4, OUTPUT);
}
void loop() {
//state 1
digitalWrite(Stepper_IN1, HIGH);
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, LOW);
delay(StepDelay);
//state 2
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, HIGH);
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, LOW);
delay(StepDelay);
//state 3
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, HIGH);
digitalWrite(Stepper_IN1, LOW);
delay(StepDelay);
//state 4
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, LOW);
digitalWrite(Stepper_IN1, HIGH);
delay(StepDelay);
}