// #include <AccelStepper.h>
// // Define pin numbers
// #define MOTOR1_STEP_PIN 2
// #define MOTOR1_DIR_PIN 3
// #define MOTOR2_STEP_PIN 4
// #define MOTOR2_DIR_PIN 5
// #define MOTOR3_STEP_PIN 6
// #define MOTOR3_DIR_PIN 7
// #define MOTOR4_STEP_PIN 8
// #define MOTOR4_DIR_PIN 9
// // Set the steps per revolution for your stepper motor
// #define STEPS_PER_REVOLUTION 200
// // Create an instance of the AccelStepper class for each motor
// AccelStepper motor1(AccelStepper::DRIVER, MOTOR1_STEP_PIN, MOTOR1_DIR_PIN);
// AccelStepper motor2(AccelStepper::DRIVER, MOTOR2_STEP_PIN, MOTOR2_DIR_PIN);
// AccelStepper motor3(AccelStepper::DRIVER, MOTOR3_STEP_PIN, MOTOR3_DIR_PIN);
// AccelStepper motor4(AccelStepper::DRIVER, MOTOR4_STEP_PIN, MOTOR4_DIR_PIN);
// void setup() {
// // Set the maximum speed and acceleration for each motor
// motor1.setMaxSpeed(1000.0);
// motor1.setAcceleration(500.0);
// motor2.setMaxSpeed(1000.0);
// motor2.setAcceleration(500.0);
// motor3.setMaxSpeed(1000.0);
// motor3.setAcceleration(500.0);
// motor4.setMaxSpeed(1000.0);
// motor4.setAcceleration(500.0);
// }
// void loop() {
// // Move each motor in a circular pattern for omnidirectional movement
// motor1.moveTo(STEPS_PER_REVOLUTION);
// motor2.moveTo(STEPS_PER_REVOLUTION);
// motor3.moveTo(STEPS_PER_REVOLUTION);
// motor4.moveTo(STEPS_PER_REVOLUTION);
// // Run the motors
// while (motor1.distanceToGo() != 0 || motor2.distanceToGo() != 0 || motor3.distanceToGo() != 0 || motor4.distanceToGo() != 0) {
// motor1.run();
// motor2.run();
// motor3.run();
// motor4.run();
// }
// // Pause before the next movement
// delay(1000);
// }
const int stepPin1 = 2;
const int dirPin1 = 3;
const int stepPin2 = 4;
const int dirPin2 = 5;
const int stepPin3 = 6;
const int dirPin3 = 7;
const int stepPin4 = 8;
const int dirPin4 = 9;
const int joystickXPin = A0;
const int joystickYPin = A1;
void setup() {
// Initialize the stepper motor pins as outputs
pinMode(stepPin1, OUTPUT);
pinMode(dirPin1, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
pinMode(stepPin3, OUTPUT);
pinMode(dirPin3, OUTPUT);
pinMode(stepPin4, OUTPUT);
pinMode(dirPin4, OUTPUT);
// Initialize the joystick pins as inputs
pinMode(joystickXPin, INPUT);
pinMode(joystickYPin, INPUT);
}
void loop() {
// Read the values of the joystick's x and y pins
int joystickXValue = analogRead(joystickXPin);
int joystickYValue = analogRead(joystickYPin);
// Map the joystick values to a range of -255 to 255
int motorSpeed1 = map(joystickXValue, 0, 1023, -255, 255);
int motorSpeed2 = map(joystickYValue, 0, 1023, -255, 255);
int motorSpeed3 = map(joystickXValue, 0, 1023, -255, 255);
int motorSpeed4 = map(joystickYValue, 0, 1023, -255, 255);
// Set the direction and speed of each stepper motor
if (motorSpeed1 > 0) {
digitalWrite(dirPin1, HIGH);
analogWrite(stepPin1, motorSpeed1);
} else {
digitalWrite(dirPin1, LOW);
analogWrite(stepPin1, -motorSpeed1);
}
if (motorSpeed2 > 0) {
digitalWrite(dirPin2, HIGH);
analogWrite(stepPin2, motorSpeed2);
} else {
digitalWrite(dirPin2, LOW);
analogWrite(stepPin2, -motorSpeed2);
}
if (motorSpeed3 > 0) {
digitalWrite(dirPin3, HIGH);
analogWrite(stepPin3, motorSpeed3);
} else {
digitalWrite(dirPin3, LOW);
analogWrite(stepPin3, -motorSpeed3);
}
if (motorSpeed4 > 0) {
digitalWrite(dirPin4, HIGH);
analogWrite(stepPin4, motorSpeed4);
} else {
digitalWrite(dirPin4, LOW);
analogWrite(stepPin4, -motorSpeed4);
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
stepper1:A-
stepper1:A+
stepper1:B+
stepper1:B-
stepper2:A-
stepper2:A+
stepper2:B+
stepper2:B-
stepper3:A-
stepper3:A+
stepper3:B+
stepper3:B-
stepper4:A-
stepper4:A+
stepper4:B+
stepper4:B-
drv1:ENABLE
drv1:MS1
drv1:MS2
drv1:MS3
drv1:RESET
drv1:SLEEP
drv1:STEP
drv1:DIR
drv1:GND.1
drv1:VDD
drv1:1B
drv1:1A
drv1:2A
drv1:2B
drv1:GND.2
drv1:VMOT
drv2:ENABLE
drv2:MS1
drv2:MS2
drv2:MS3
drv2:RESET
drv2:SLEEP
drv2:STEP
drv2:DIR
drv2:GND.1
drv2:VDD
drv2:1B
drv2:1A
drv2:2A
drv2:2B
drv2:GND.2
drv2:VMOT
drv3:ENABLE
drv3:MS1
drv3:MS2
drv3:MS3
drv3:RESET
drv3:SLEEP
drv3:STEP
drv3:DIR
drv3:GND.1
drv3:VDD
drv3:1B
drv3:1A
drv3:2A
drv3:2B
drv3:GND.2
drv3:VMOT
drv4:ENABLE
drv4:MS1
drv4:MS2
drv4:MS3
drv4:RESET
drv4:SLEEP
drv4:STEP
drv4:DIR
drv4:GND.1
drv4:VDD
drv4:1B
drv4:1A
drv4:2A
drv4:2B
drv4:GND.2
drv4:VMOT
vcc1:VCC
gnd1:GND
vcc2:VCC
gnd2:GND
vcc3:VCC
gnd3:GND
vcc4:VCC
gnd4:GND
joystick1:VCC
joystick1:VERT
joystick1:HORZ
joystick1:SEL
joystick1:GND