Hi all,
i developed a sketch, where the stepper motor, driven by the easydriver board will turn, but constantly read some buttons, in order to start turning or stop, when the button is hit. It works, but the motor shakes while running. To constantly be able to check button state, the stepper function is called and turns 26 microsteps.
The code (part), is as follow:
void loop() {
check_mode();
switch (operation_mode) {
case 'A':
Automatic_Mode();
break;
case 'C':
Manual_Close();
break;
case 'O':
Manual_Open();
break;
case 'P':
break;
}
}
void check_mode() {
automatic.listen(); manual_close.listen(); manual_open.listen();
if (automatic.onPress()) {
if (operation_mode == 'A') {
operation_mode = 'P';
} else {
operation_mode = 'A';
}
}
if (manual_close.onPress()) {
if (operation_mode == 'C') {
operation_mode = 'P';
} else {
operation_mode = 'C';
}
}
if (manual_open.onPress()) {
if (operation_mode == 'O') {
operation_mode = 'P';
} else {
operation_mode = 'O';
}
}
}
void Manual_Close() {
delay(500);
while(digitalRead(stop_close) == LOW && operation_mode == 'C') {
direction = 'C';
EasyDriverEnable();
BlindMotor();
check_mode();
}
EasyDriverDisable();
}
void BlindMotor() {
if (direction == 'O')
digitalWrite(MotorDir, HIGH);
if (direction == 'C')
digitalWrite(MotorDir, LOW);
int dist = 0;
// the motor makes a full turn with 1600 microsteps. So, this move makes the motor turns 1/64th of a full turn = 25 microsteps.
while (dist < 26) {
digitalWrite(MotorStep, HIGH);
delayMicroseconds(280);
digitalWrite(MotorStep, LOW);
delayMicroseconds(280);
dist = dist + 1;
}
}
Question: is there a way to tune the BlindMotor function so it moves smoother? I did try, but with not luck. I need the motor to run slow (not too slow).
Could anyone with better skills than me help?
Thanks in advance,
Paulo