#include <Stepper.h>
#define button1 6
#define button2 7
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for 1.8 degree step angle 200 will maximum
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); // L298n port IA IB IC ID accordingly
void setup() {
pinMode(button1, INPUT_PULLUP); // Input pulse to arduino by pressing button 1
pinMode(button2, INPUT_PULLUP); // Input pulse to arduino by pressing button 2
myStepper.setSpeed(60); // RPM, 60 Rotation per minute
}
void loop() {
if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // If no key is pressed
}
if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // if one is idle (L) and the other one (R) key pressed
myStepper.step(stepsPerRevolution); // Stepper motor rotates CW (Clockwise)
delayMicroseconds(100); // pause time after per steps 100u seconds = 0.1 mili seconds
}
else if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW) { // if other one (R) is idle and the one (L) key pressed
myStepper.step(-stepsPerRevolution); // Stepper motor rotates CCW (Anticlockwise)
delayMicroseconds(100); // pause time after per steps 100u seconds = 0.1 mili seconds
}
}