都是借来的代码 (https://reprap.org/forum/read.php?219,166111,711833#msg-711833)
#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38#include "AccelStepper.h"
AccelStepper stepper(1, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN);
void setup()
{
pinMode(X_ENABLE_PIN , OUTPUT);
digitalWrite(X_ENABLE_PIN , LOW);
stepper.setSpeed(400);
}void loop()
{
stepper.runSpeed();
}
还需要借下面的两个文件:
https://raw.githubusercontent.com/adafruit/AccelStepper/master/AccelStepper.cpp
https://raw.githubusercontent.com/adafruit/AccelStepper/master/AccelStepper.h
项目地址:
https://github.com/adafruit/AccelStepper
最近编辑记录 smartcar (2019-02-25 23:37:53)
离线
#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2#define Y_STEP_PIN 60
#define Y_DIR_PIN 61
#define Y_ENABLE_PIN 56
#define Y_MIN_PIN 14
#define Y_MAX_PIN 15#define Z_STEP_PIN 46
#define Z_DIR_PIN 48
#define Z_ENABLE_PIN 62
#define Z_MIN_PIN 18
#define Z_MAX_PIN 19#define E_STEP_PIN 26
#define E_DIR_PIN 28
#define E_ENABLE_PIN 24#define Q_STEP_PIN 36
#define Q_DIR_PIN 34
#define Q_ENABLE_PIN 30#define SDPOWER -1
#define SDSS 53
#define LED_PIN 13#define FAN_PIN 9
#define PS_ON_PIN 12
#define KILL_PIN -1#define HEATER_0_PIN 10
#define HEATER_1_PIN 8
#define TEMP_0_PIN 13 // ANALOG NUMBERING
#define TEMP_1_PIN 14 // ANALOG NUMBERINGvoid setup() {
pinMode(FAN_PIN , OUTPUT);
pinMode(HEATER_0_PIN , OUTPUT);
pinMode(HEATER_1_PIN , OUTPUT);
pinMode(LED_PIN , OUTPUT);
pinMode(X_STEP_PIN , OUTPUT);
pinMode(X_DIR_PIN , OUTPUT);
pinMode(X_ENABLE_PIN , OUTPUT);
pinMode(Y_STEP_PIN , OUTPUT);
pinMode(Y_DIR_PIN , OUTPUT);
pinMode(Y_ENABLE_PIN , OUTPUT);
pinMode(Z_STEP_PIN , OUTPUT);
pinMode(Z_DIR_PIN , OUTPUT);
pinMode(Z_ENABLE_PIN , OUTPUT);
pinMode(E_STEP_PIN , OUTPUT);
pinMode(E_DIR_PIN , OUTPUT);
pinMode(E_ENABLE_PIN , OUTPUT);
pinMode(Q_STEP_PIN , OUTPUT);
pinMode(Q_DIR_PIN , OUTPUT);
pinMode(Q_ENABLE_PIN , OUTPUT);
digitalWrite(X_ENABLE_PIN , LOW);
digitalWrite(Y_ENABLE_PIN , LOW);
digitalWrite(Z_ENABLE_PIN , LOW);
digitalWrite(E_ENABLE_PIN , LOW);
digitalWrite(Q_ENABLE_PIN , LOW);
}void loop () {
if (millis() %1000 <500)
digitalWrite(LED_PIN, HIGH);
else
digitalWrite(LED_PIN, LOW);
if (millis() %1000 <300) {
digitalWrite(HEATER_0_PIN, HIGH);
digitalWrite(HEATER_1_PIN, LOW);
digitalWrite(FAN_PIN, LOW);
} else if (millis() %1000 <600) {
digitalWrite(HEATER_0_PIN, LOW);
digitalWrite(HEATER_1_PIN, HIGH);
digitalWrite(FAN_PIN, LOW);
} else {
digitalWrite(HEATER_0_PIN, LOW);
digitalWrite(HEATER_1_PIN, LOW);
digitalWrite(FAN_PIN, HIGH);
}if (millis() %10000 <5000) {
digitalWrite(X_DIR_PIN , HIGH);
digitalWrite(Y_DIR_PIN , HIGH);
digitalWrite(Z_DIR_PIN , HIGH);
digitalWrite(E_DIR_PIN , HIGH);
digitalWrite(Q_DIR_PIN , HIGH);
}
else {
digitalWrite(X_DIR_PIN , LOW);
digitalWrite(Y_DIR_PIN , LOW);
digitalWrite(Z_DIR_PIN , LOW);
digitalWrite(E_DIR_PIN , LOW);
digitalWrite(Q_DIR_PIN , LOW);
}digitalWrite(X_STEP_PIN , HIGH);
digitalWrite(Y_STEP_PIN , HIGH);
digitalWrite(Z_STEP_PIN , HIGH);
digitalWrite(E_STEP_PIN , HIGH);
digitalWrite(Q_STEP_PIN , HIGH);
delay(1);
digitalWrite(X_STEP_PIN , LOW);
digitalWrite(Y_STEP_PIN , LOW);
digitalWrite(Z_STEP_PIN , LOW);
digitalWrite(E_STEP_PIN , LOW);
digitalWrite(Q_STEP_PIN , LOW);
}
离线
#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38void setup() {
pinMode(X_STEP_PIN , OUTPUT);
pinMode(X_DIR_PIN , OUTPUT);
pinMode(X_ENABLE_PIN , OUTPUT);
digitalWrite(X_ENABLE_PIN , LOW);
}void loop () {
digitalWrite(X_DIR_PIN , HIGH);digitalWrite(X_STEP_PIN, LOW);
delay(1);//delay ms
digitalWrite(X_STEP_PIN, HIGH);
}
GPIO 模拟PWM驱动步进电机.
离线
微雕大师 V1.1.0.0 控制 写字机散件.
离线