// test a stepper motor with a Pololu A4988 driver board, onboard led will flash at each step
// this version uses delay() to manage timing
byte directionPin = 8;
byte stepPin = 9;
byte ledPin = 13;
// int pulseWidthMicros = 20; // microsecondo
int pulseWidthSec = 10; // microsecondo
int statostart;
void setup() {
// Serial.begin(9600); // normal speed
// 300 , 1200 , 2400 , 4800 , 9600 , 14400 , 38400 , 57600 , 115200 , 230400 , 460800 , 921600
// Serial.begin(921600); // fastest speed, consuming a lot of cpu usage
// Serial.println("Starting StepperTest");
digitalWrite(ledPin, LOW);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// pinMode(2, INPUT_PULLUP);
// pinMode(4, INPUT_PULLUP);
}
void loop() {
// statostart = digitalRead(2);
// byte btn_left = digitalRead(4);
// byte btn_right = digitalRead(7);
// if (btn_left == LOW) {
// if (btn_left == HIGH) {
// digitalWrite(directionPin, LOW);
// digitalWrite(stepPin, HIGH);
// // delayMicroseconds(pulseWidthMicros);
// delay(pulseWidthSec);
// Serial.println("Step Pressed Left:" + String(btn_left));
// digitalWrite(stepPin, LOW);
// }
digitalWrite(directionPin, HIGH);
digitalWrite(stepPin, HIGH);
delay(pulseWidthSec);
// Serial.println("Run Forwarding");
digitalWrite(stepPin, LOW);
}