// Stepper motor on Wokwi!
#include <Stepper.h>
int count = 0;
int newcount;
const int button = 13;
const int stepsPerRevolution = 1200; // 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() {
pinMode(button, INPUT_PULLUP);
// set the speed at 60 rpm:
myStepper.setSpeed(10);
// initialize the serial port:
Serial.begin(9600);
}
void loop()
{
int buttonVal = digitalRead(button);
if (buttonVal == LOW)
{
Serial.print("pressed ");
Serial.println(count);
delay(150);
newcount = count+1;
count=newcount;
}
if (count == 1)
{
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
newcount = count+1;
count = newcount;
delay(500);
}
if (newcount == 3)
{
// step one revolution in one direction:
Serial.println("counter clockwise");
myStepper.step(-stepsPerRevolution);
newcount = count+1;
count = newcount;
delay(500);
}
if (count >=4)
{
count = 0;
}
}