|
#include "Motion86.h"
// Generate machine objects. You can use up to three machines, machine 0~2, each with three axes.
Machine machine(0);
// Stepper Motor enable pin。
int EnablePin = 4;
void setup() {
while (!Serial);
pinMode(EnablePin, OUTPUT);
// If necessary, the direction of motion of the axis can be reversed.
// In this example, you need to reverse the direction of the x-axis and the y-axis.
machine.config_ReverseDirection(AXIS_X);
machine.config_ReverseDirection(AXIS_Y);
// PPU (pulse per unit) is a virtual unit of length, depending on different needs.
// In this example, the unit length of the x-axis is set to 80 pulses, which corresponds to 1 mm in actual application.
machine.config_PPU(AXIS_X, 80.0);
machine.config_PPU(AXIS_Y, 80.0);
machine.config_PPU(AXIS_Z, 1600.0);
// Before controlling, the machine must be started.
machine.machineOn();
// Set the Machine to jog mode and trigger it with the button it is connected to.
// machine.beginJog(27, 28, 32, 3, 16, 17, false);
// If the Machine is set to Inc Jog mode, the offset should be configured to set how many millimeters each click moves.
machine.beginJog(27, 28, 32, 3, 16, 17, true);
machine.setJogOffset(1.0);
// Feedrate in Jog mode.
machine.setJogSpeed(600);
// Start the stepper motor.
digitalWrite(EnablePin, LOW);
}
void loop() {
Serial.print("Jog position = ");
Serial.print(machine.getJogPos(AXIS_X));
Serial.print(", ");
Serial.print(machine.getJogPos(AXIS_Y));
Serial.print(", ");
Serial.println(machine.getJogPos(AXIS_Z));
delay(500);
}
|