// Stepper motor on Wokwi!

#include <Stepper.h>
int pb1 = 5;
int pb2 = 13;
int pot = A0;
int val = 0;
int val2 = 0;
int valpot = 0;

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 Setspeed(30);
 // myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
  pinMode(pb1, INPUT_PULLUP);
  pinMode(pb2, INPUT_PULLUP);
  pinMode(A0, INPUT);
}

void loop() {
   // set the speed Setspeed by Potensio
   valpot = analogRead(pot);
   Serial.println(valpot);
int Speed = map(valpot, 0, 1023, 0, 100);
  // step one revolution  in one direction:
  val = digitalRead(pb1);
  if (val==LOW){
 
  Serial.println("clockwise");
    myStepper.setSpeed(Speed);
  myStepper.step(stepsPerRevolution);
  delay(500);
 }
  // step one revolution in the other direction:
{
val2 = digitalRead(pb2);
if(val2==LOW){
 
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
  myStepper.step(0);
}
} 
}