#include <Stepper.h>
int stepsPerRevolution = 1024;
int motSpeed = 25;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int R = 0;
const int buttonPin1 = 4;
const int buttonPin2 = 3;
const int buttonPin3 = 1;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int totalSteps = 0;
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
Serial.begin(9600);
myStepper.setSpeed(motSpeed);
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
if (buttonState1 == LOW && totalSteps < 500) {
myStepper.step(5); // Pasos por click
totalSteps+=5;
}
if (buttonState2 == LOW && totalSteps >= 5) {
myStepper.step(-5); // Pasos por click
totalSteps-=5;
}
Serial.println(R);
if (R == 0){
for (int count = 0; count < 5; count++) {
myStepper.step(stepsPerRevolution);
delay(1000);
myStepper.step((-stepsPerRevolution));
delay(1000);
R++;
}
}
}