// Define the connections to your stepper motor drivers and button
const int stepPin1 = 2; // Step pin of the first stepper motor driver
const int dirPin1 = 3; // Direction pin of the first stepper motor driver
const int stepPin2 = 4; // Step pin of the second stepper motor driver
const int dirPin2 = 5; // Direction pin of the second stepper motor driver
const int stepPin3 = 6; // Step pin of the third stepper motor driver
const int dirPin3 = 7; // Direction pin of the third stepper motor driver
const int stepPin4 = 8; // Step pin of the fourth stepper motor driver
const int dirPin4 = 9; // Direction pin of the fourth stepper motor driver
const int stepPin5 = 10; // Step pin of the fifth stepper motor driver
const int dirPin5 = 11; // Direction pin of the fifth stepper motor driver
const int stepPin6 = 12; // Step pin of the sixth stepper motor driver
const int dirPin6 = 13; // Direction pin of the sixth stepper motor driver
const int buttonPin = A0; // Pin connected to the push button (use A0 for analog pin)
bool motorRunning = false; // Flag to track motor state
void setup() {
// Set the motor control 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);
pinMode(stepPin5, OUTPUT);
pinMode(dirPin5, OUTPUT);
pinMode(stepPin6, OUTPUT);
pinMode(dirPin6, OUTPUT);
// Set the button pin as input with internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Check if the button is pressed to toggle motor state
if (digitalRead(buttonPin) == LOW) { // LOW indicates the button is pressed
motorRunning = !motorRunning; // Toggle motor state
delay(200); // Debounce delay to avoid multiple detections
}
// Control motor 1
if (motorRunning) {
digitalWrite(dirPin1, HIGH); // Set direction for motor 1 (clockwise)
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500); // Adjust this delay according to motor 1's step speed
digitalWrite(stepPin1, LOW);
delayMicroseconds(500); // Adjust this delay according to motor 1's step speed
}
// Control motor 2
if (motorRunning) {
digitalWrite(dirPin2, HIGH); // Set direction for motor 2 (clockwise)
digitalWrite(stepPin2, HIGH);
delayMicroseconds(500); // Adjust this delay according to motor 2's step speed
digitalWrite(stepPin2, LOW);
delayMicroseconds(500); // Adjust this delay according to motor 2's step speed
}
// Control motor 3
if (motorRunning) {
digitalWrite(dirPin3, HIGH); // Set direction for motor 3 (clockwise)
digitalWrite(stepPin3, HIGH);
delayMicroseconds(500); // Adjust this delay according to motor 3's step speed
digitalWrite(stepPin3, LOW);
delayMicroseconds(500); // Adjust this delay according to motor 3's step speed
}
// Control motor 4
if (motorRunning) {
digitalWrite(dirPin4, HIGH); // Set direction for motor 4 (clockwise)
digitalWrite(stepPin4, HIGH);
delayMicroseconds(500); // Adjust this delay according to motor 4's step speed
digitalWrite(stepPin4, LOW);
delayMicroseconds(500); // Adjust this delay according to motor 4's step speed
}
// Control motor 5
if (motorRunning) {
digitalWrite(dirPin5, HIGH); // Set direction for motor 5 (clockwise)
digitalWrite(stepPin5, HIGH);
delayMicroseconds(500); // Adjust this delay according to motor 5's step speed
digitalWrite(stepPin5, LOW);
delayMicroseconds(500); // Adjust this delay according to motor 5's step speed
}
// Control motor 6
if (motorRunning) {
digitalWrite(dirPin6, HIGH); // Set direction for motor 6 (clockwise)
digitalWrite(stepPin6, HIGH);
delayMicroseconds(500); // Adjust this delay according to motor 6's step speed
digitalWrite(stepPin6, LOW);
delayMicroseconds(500); // Adjust this delay according to motor 6's step speed
}
}