// Stepper motor on Wokwi!
/*不使用库
int pinZou=2;
int pinR=6;
int pinL=7;
int Bm=8; //B-
int Bp=9; //B+
int Ap=10; //A+
int Am=11; //A-
void setup()
{
pinMode(pinZou, INPUT_PULLUP);
pinMode(pinR, INPUT_PULLUP);
pinMode(pinL, INPUT_PULLUP);
pinMode(Bm, OUTPUT);
pinMode(Bp, OUTPUT);
pinMode(Ap, OUTPUT);
pinMode(Am, OUTPUT);
}
void loop() {
delay(100);
Serial.println("anzou");
if(digitalRead(pinZou)==LOW)
{
if(digitalRead(pinR)==LOW)//右转
{
delay(20);digitalWrite(Bm,LOW) ; digitalWrite(Ap,HIGH);
delay(20);digitalWrite(Ap,LOW) ; digitalWrite(Bp,HIGH);
delay(20);digitalWrite(Bp,LOW) ; digitalWrite(Am,HIGH);
delay(20);digitalWrite(Am,LOW) ; digitalWrite(Bm,HIGH);
}
if(digitalRead(pinL)==LOW)
{
//Serial.println("zuozuozuo"); //左转
delay(20);digitalWrite(Am,LOW) ; digitalWrite(Bp,HIGH);
delay(20);digitalWrite(Bp,LOW) ; digitalWrite(Ap,HIGH);
delay(20);digitalWrite(Ap,LOW) ; digitalWrite(Bm,HIGH);
delay(20);digitalWrite(Bm,LOW) ; digitalWrite(Am,HIGH);
}
}
}
*/
#include<Stepper.h>
int pinZou=2;
int pinR=6;
int pinL=7;
Stepper mys(200,8,9,10,11);
void setup()
{
pinMode(pinZou, INPUT_PULLUP);
pinMode(pinR, INPUT_PULLUP);
pinMode(pinL, INPUT_PULLUP);
mys.setspeed(30);
}
void loop() {
delay(100);
if(digitalRead(pinZou)==LOW)
{
Serial.println("anzou");
if(digitalRead(pinR)==LOW)
{
}
if(digitalRead(pinL)==LOW)
{
}
}
}