// Stepper motor on Wokwi!
#include <Stepper.h>
#define RIGHT_BUTTON 2
#define LEFT_BUTTON 3
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 motor(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
motor.setSpeed(100);
pinMode(RIGHT_BUTTON, INPUT_PULLUP);
pinMode(LEFT_BUTTON, INPUT_PULLUP);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
int right = digitalRead((RIGHT_BUTTON));
int left = digitalRead((LEFT_BUTTON));
if (left == LOW) {
motor.step(-1);
digitalWrite(LEFT_BUTTON, HIGH);
}
if (right == LOW) {
motor.step(1);
digitalWrite(RIGHT_BUTTON, HIGH);
}
}