// Stepper motor on Wokwi!
#include <Stepper.h>
int val; // variable to read the value from the analog pin
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(180);
// initialize the serial port:
Serial.begin(9600);
pinMode(2, INPUT);//sobe
pinMode(4, INPUT);//sobe 10
pinMode(3,INPUT);//desce
pinMode(5,INPUT);//desce 10
val = 200;
}
void loop() {
// reads the value of the potentiometer
// scale it to use it with the step motor
while(digitalRead(2)==HIGH){
Serial.println("horário");
myStepper.step(val);
delay(500);
Serial.println(val);
}
while(digitalRead(4)==HIGH){
Serial.println("horário");
myStepper.step(val*10);
delay(500);
Serial.println(val*10);
}
while(digitalRead(3)==HIGH){
Serial.println("Antihorário");
myStepper.step(-val);
delay(500);
Serial.println(-val);
}
while(digitalRead(5)==HIGH){
Serial.println("horário");
myStepper.step(-val*10);
delay(500);
Serial.println(-val*10);
}
}