27-02-2022, 20:30
Brak schematu, wg Twojego kodu przycisk powinien zwierać pin btn1 do VCC, a pin btn1 powinien być podłączony rezystorem 10k na stałe do GND.
Natomiast nie wiem co tu sobie poustawiałeś za prędkości i przyspieszenia, nie każdy silnik da z tym radę. Ale rozumiem, że jakkolwiek to już działa, silnik kręcił i reszta była OK.
Kod:
/ Include the AccelStepper library:
#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
int btn1 = 5;
bool start;
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
// Set the maximum speed and acceleration:
stepper.setMaxSpeed(8000);
stepper.setAcceleration(500);
pinMode(btn1,INPUT);
}
void loop() {
if(digitalRead(btn1) == HIGH) start=1;
if(start)
{
stepper.moveTo(32000);
stepper.runToPosition();
}
}
Miło być decenianym https://buycoffee.to/kaczakat