Muovere Passo passo tramite pulsante

Niente ho provato varie soluzioni ma niente sono riuscito a fare andare il motore a destra premendo il tasto 1 ma premendo il tasto 2 non succede nulla ]:slight_smile:
Se lo setto a 1 invece di 0 sull'IF mi va di continuo destra sinistra come se facesse il loop dei 500 passi prima positivi poi negativi all'infinito

Nessuno mi saprebbe aiutare?

int DIR_PIN_M1 =3; //7
int STEP_PIN_M1 =2; //5
int SLEEP = 6; // PIN 12 = SLP
int DIR_PIN_M2 =3;
int STEP_PIN_M2 =2;

const int buttonPin = 10; //Setting button number 1 to Pin 2
int buttonState = 1; //Setting button state to off

const int buttonPin1 = 12; //Setting button number 1 to Pin 2

void setup() {
pinMode(DIR_PIN_M1, OUTPUT);
pinMode(STEP_PIN_M1, OUTPUT);

}

void loop(){

//specifica numero giri e tempo di attesa
if ( digitalRead(buttonPin1) == 1){
digitalWrite(SLEEP, LOW); } // Sveglia il motore.
if ( digitalRead(buttonPin1) == 0){
digitalWrite(SLEEP, HIGH); } // Sveglia il motore.
if ( digitalRead(buttonPin) == 0) {
rotateDeg(-500, 0.7);
delay(000);
digitalWrite(SLEEP, LOW); // Spegne il motore
}

if ( digitalRead(buttonPin) == 1) {
rotateDeg(500, 0.7);
delay(000);
}
}

void rotateDeg(float deg, float speed){
//rotate a specific number of degrees (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (deg > 0)? HIGH:LOW;
digitalWrite(DIR_PIN_M1,dir);

int steps = abs(deg)*(1/0.225);
float usDelay = (1/speed) *70;

for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_M1, HIGH);
delayMicroseconds(usDelay);

digitalWrite(STEP_PIN_M1, LOW);
delayMicroseconds(usDelay);
}

}
void rotate_M2(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);

digitalWrite(DIR_PIN_M2,dir);

float usDelay = (1/speed) * 70;

for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_M2, HIGH);
delayMicroseconds(usDelay);

digitalWrite(STEP_PIN_M2, LOW);
delayMicroseconds(usDelay);
}

}