Hi
I need some guidance on the sketch below. I am trying to have a stepper motor move forward and backwards after pushing
a button.
Thanks Rmac
#include <buttons.h>
#include <AccelStepper.h>
#include <AFMotor.h>
/*
One switch stepper motor Program
Turns on and off digital pin connected to pin 5 as output when pressing pushbutton
(Park ) attached to digital pins 2
The circuit:
- Not sure of Motor circut yet , but output from digital pins 5
- pushbutton is attached to digital pin 2 +5V
- 10K resistors attached to digital pins 2 from ground
*/
// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPinPark = 2; //Setting Park button to Pin 2
int buttonStatePark = 0; //Setting Park button state to off
const int Pin1 = 5; // Pin output number
AF_Stepper motor(200, 2);
void setup() {
// initialize the pin as an output:
pinMode (Pin1,OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinPark, INPUT);
motor.setSpeed(10); // 10 rpm
}
void loop(){
// read the state of the Park pushbutton value:
{ buttonStatePark = digitalRead(buttonPinPark); //code for Park button
// check if the Park pushbutton is pressed.
// if it is, the buttonStatePark is HIGH:
if (buttonStatePark == HIGH) {
// Have output on pin 5 (5 volts:
digitalWrite (Pin1, HIGH);
??? (“Single coil steps”); Dont know what to do here
motor.step(200, FORWARD, SINGLE);
motor.step(200, BACKWARD, SINGLE);
buttonStatePark = digitalRead(buttonPinPark);
if (buttonStatePark == LOW)
digitalWrite(Pin1,LOW);
else {
// Set Pin1 Off:
digitalWrite(Pin1, LOW);
}
}
}
}