|
#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, you can reverse the direction of the motion axis.
// In this example, you need to reverse the direction of the x-axis and y-axis.
machine.config_ReverseDirection(AXIS_X);
machine.config_ReverseDirection(AXIS_Y);
// PPU (pulse per unit) is a virtual length unit, 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();
machine.setDefaultFeedrate(400);
// Start the stepper motor.
digitalWrite(EnablePin, LOW);
}
void loop() {
// Move left to (-10, 0).
machine.line(-10, 0, 0);
// Move 90 degrees clockwise with a radius of 10 to (0, 10).
machine.arcXY(10, 0, 10, true);
// Move down to (0, -10).
machine.line(0, -10, 0);
// Move 90 degrees counterclockwise with a radius of 10 to (10, 0).
machine.arcXY(10, 10, 0, false);
// Move left to (0, 0).
machine.line(0, 0, 0);
// Movement stops after 1 second.
delay(1000);
machine.emgStop();
machine.clearEMGStop();
}
|