89 lines
1.5 KiB
C++
89 lines
1.5 KiB
C++
/*
|
|
#include <AccelStepper.h>
|
|
#include <AFMotor.h>
|
|
|
|
AF_Stepper motor1(4096, 2);
|
|
|
|
|
|
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
|
|
void forwardstep() {
|
|
motor1.onestep(FORWARD, INTERLEAVE);
|
|
}
|
|
void backwardstep() {
|
|
motor1.onestep(BACKWARD, INTERLEAVE);
|
|
}
|
|
|
|
AccelStepper stepper(forwardstep, backwardstep); // use functions to step
|
|
|
|
void setup(){
|
|
//Serial.begin(115200);
|
|
|
|
stepper.setMaxSpeed(5000);
|
|
stepper.setSpeed(-900); // Go Up
|
|
//stepper.setSpeed(1000); // Go Down
|
|
}
|
|
|
|
|
|
int stepper_speed = 0;
|
|
|
|
void loop(){
|
|
//accelerate(350, 900, 10);
|
|
|
|
//Serial.println(stepper_speed);
|
|
stepper.runSpeed();
|
|
}
|
|
|
|
void accelerate(int start_speed, int finish_speed, int speed_step) {
|
|
|
|
if (stepper_speed < start_speed) {
|
|
stepper_speed = start_speed;
|
|
}
|
|
|
|
static uint16_t last_millis;
|
|
static uint16_t current_millis;
|
|
current_millis = millis();
|
|
|
|
if (current_millis-last_millis > 100) {
|
|
stepper_speed += speed_step;
|
|
last_millis = current_millis;
|
|
}
|
|
|
|
|
|
if (stepper_speed >= finish_speed) {
|
|
stepper_speed = finish_speed;
|
|
}
|
|
|
|
stepper.setSpeed(-stepper_speed);
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
#include <Stepper.h>
|
|
|
|
int in1Pin = 12;
|
|
int in2Pin = 11;
|
|
int in3Pin = 10;
|
|
int in4Pin = 9;
|
|
|
|
Stepper motor(32, in1Pin, in2Pin, in3Pin, in4Pin);
|
|
|
|
void setup() {
|
|
pinMode(in1Pin, OUTPUT);
|
|
pinMode(in2Pin, OUTPUT);
|
|
pinMode(in3Pin, OUTPUT);
|
|
pinMode(in4Pin, OUTPUT);
|
|
|
|
Serial.begin(9600);
|
|
motor.setSpeed(500);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
if (Serial.available()) {
|
|
int steps = Serial.parseInt();
|
|
Serial.println(steps);
|
|
motor.step(steps);
|
|
}
|
|
}
|