// Define pins for Motor 1 (e.g., left fold)
const int dirPin1 = 2;
const int stepPin1 = 3;
// Define pins for Motor 2 (e.g., right fold)
const int dirPin2 = 4;
const int stepPin2 = 5;
// Define pins for Motor 3 (e.g., bottom fold)
const int dirPin3 = 6;
const int stepPin3 = 7;
const int stepsPerRevolution = 200; // Adjust based on your stepper motor's folding needs
void setup() {
// Set Motor 1 pins as Outputs
pinMode(stepPin1, OUTPUT);
pinMode(dirPin1, OUTPUT);
// Set Motor 2 pins as Outputs
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
// Set Motor 3 pins as Outputs
pinMode(stepPin3, OUTPUT);
pinMode(dirPin3, OUTPUT);
}
void loop() {
// Step 1: Motor 1 does the left fold
foldMotor1();
// Delay between folds for stability
delay(1000); // Adjust as necessary
// Step 2: Motor 2 does the right fold
foldMotor2();
// Delay between folds for stability
delay(1000); // Adjust as necessary
// Step 3: Motor 3 does the bottom fold
foldMotor3();
// Delay before resetting for the next round of folding
delay(2000); // Adjust based on how long the whole process takes
}
void foldMotor1() {
// Set Motor 1 direction to forward (fold clothes)
digitalWrite(dirPin1, HIGH);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
}
// Delay to hold the position
delay(500);
// Set Motor 1 direction to backward (reset fold)
digitalWrite(dirPin1, LOW);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
}
}
void foldMotor2() {
// Set Motor 2 direction to forward (fold clothes)
digitalWrite(dirPin2, HIGH);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
// Delay to hold the position
delay(500);
// Set Motor 2 direction to backward (reset fold)
digitalWrite(dirPin2, LOW);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
}
void foldMotor3() {
// Set Motor 3 direction to forward (fold clothes)
digitalWrite(dirPin3, HIGH);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin3, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin3, LOW);
delayMicroseconds(2000);
}
// Delay to hold the position
delay(500);
// Set Motor 3 direction to backward (reset fold)
digitalWrite(dirPin3, LOW);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin3, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin3, LOW);
delayMicroseconds(2000);
}
}