Bear with me here, as I'm a complete noob to programming and I've tried a few different ways to do this so I'm a bit confused...but I hope you guys can help me out again. I have a program, for now, that will run my motor at 50 RPM for one rotation, pause for two seconds, then reverse. Obviously this isn't very functional so I am trying to expand it to allow me to press a button for constant rotation in either direction. Each button will control its respective direction.
So far my code looks like this:
// Include the Stepper Library
#include <Stepper.h>
// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
// The amount of steps for a full revolution of your motor.
// 360 / stepAngle
const int STEPS = 400;
// Initialize the Stepper class
Stepper myStepper(STEPS, dirA, dirB);
void setup() {
// Set the RPM of the motor
myStepper.setSpeed();
// Turn on pulse width modulation
pinMode(pwmA, OUTPUT);
digitalWrite(pwmA, HIGH);
pinMode(pwmB, OUTPUT);
digitalWrite(pwmB, HIGH);
// Turn off the brakes
pinMode(brakeA, OUTPUT);
digitalWrite(brakeA, LOW);
pinMode(brakeB, OUTPUT);
digitalWrite(brakeB, LOW);
// Log some shit
Serial.begin(9600);
}
void loop() {
// Move the motor X amount of steps
myStepper.step(STEPS);
Serial.println(STEPS);
// Pause
delay(2000);
// Move the motor X amount of steps the other way
myStepper.step(-STEPS);
Serial.println(-STEPS);
// Pause
delay(2000);
}
I've tried multiple things, all fairly blindly, and using the 4-post mini buttons. I can post up those examples but I don't see them being very useful if I'm going to be using a different style button. If someone could please help, I'd much appreciate it!