#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper = AccelStepper(1, D6, D7); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
int buttonPin1 = D11;
int buttonPin2 = D12;
int buttonState1 = HIGH;
int buttonState2 = HIGH;
int motorPos = 0;
void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(400.0);
stepper.setAcceleration(200);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
}
void loop()
{
//digitalWrite(MS2pin, HIGH);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == LOW) {
Serial.println("buttonState1");
Serial.println(buttonState1);
motorPos = 500;
}
if (buttonState2 == LOW) {
Serial.println("buttonState2");
Serial.println(buttonState2);
motorPos = 1000;
}
stepper.runToNewPosition(motorPos);
}
IDE version 1.8.12
I'm using a A4988 driver to power a NEMA 17 with a Wemos D1. I have confirmed that stepper motor will run to various positions with similar "runToNewPosition" code so i'm fairly confident on my wiring. I cannot however, get them to run to a certain position when a button is pressed. I have also confirmed that the button pins are at 3.3V when unpressed and 0V/grounded when pressed, which I thought i was triggering in my code. Only one of the buttons (D12) trigger a very slight movement when I press it, the other does nothing. Any help would be greatly appreciated, let me know if you need any more information.