Hi,
I looking for way to change rotation speed, to increase rotating speed of step motor.
Sketch bellow work fine but I have not possibility to controll speed.
What should I do?
#define step_pin 3 // Define pin 3 as the steps pin
#define dir_pin 2 // Define pin 2 as the direction pin
#define MS1 5 // Define pin 5 as "MS1"
#define MS2 4 // Define pin 4 as "MS2"
#define button1 7
#define button2 8
int direction; // Variable to determine the sense of the motor
int steps = 500; // Number of steps that you want to execute (for full steps, 200 = 1 turn)
void setup() {
pinMode(MS1, OUTPUT); // Configures "MS1" as output
pinMode(MS2, OUTPUT); // Configures "MS2" as output
pinMode(dir_pin, OUTPUT); // Configures "dir_pin" as output
pinMode(step_pin, OUTPUT); // Configures "step_pin" as output
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
digitalWrite(MS1, HIGH ); // Configures the steps division (see above)
digitalWrite(MS2, HIGH); // Configures the steps division (see above)
digitalWrite(dir_pin, LOW); // Sense (HIGH = anti-clockwise / LOW = clockwise) - It can be also changed
stepper.setMaxSpeed(3000);
stepper.setAcceleration(1000);
}
void loop() {
if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // ako ni jedan taster nije pritisnut
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, LOW);
}
if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // ako je taster 1 idle, a taster 2 pritisnut
digitalWrite(dir_pin, LOW); // move in the LOW direction
digitalWrite(step_pin, LOW);
delay(3);
digitalWrite(step_pin, HIGH);
delay(3);
} else if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW) { // ako je taster 2 idle, a taster 1 pritisnut
digitalWrite(dir_pin, HIGH); // move in HIGH direction
digitalWrite(step_pin, LOW);
delay(3);
digitalWrite(step_pin, HIGH);
delay(3);
}
}