I'm using a program where the stepper motor moves a cart with cup and bowl to a position; holds that position while a servo motor to help dispense cereal and fluid. I want the stepper motor to move in three positions for each servo motor then resets itself to its initial position and repeat the process.
Here is the code I'm working with at the moment.
#include <Servo.h>
#include <Stepper.h>
Servo myservo1; // Cereal Servo Motor
Servo myservo2; // Fluid 1 Servo Motor
Servo myservo3; // Fluid 2 Servo Motor
void setup() {
myservo1.attach(2); // attaches the servo on pin 2 to the servo object
myservo2.attach(3); // attaches the servo on pin 3 to the servo object
myservo3.attach(5); // attaches the servo on pin 5 to the servo object
}
void loop() {
// Step Motor Code Move to Postition 1
// WORK IN PROGRESS
// Code To Turn The Cereal Dispenser
myservo1.attach(2);
// attaches the servo on pin 2 to the servo object
delay(15);
myservo1.write(180);
// sets the servo position according to the scaled value
delay(5000);
// waits 1000ms for it to get to the position
myservo1.detach();
delay(10000);
// Step Motor Code Move to Position 2
// WORK IN PROGRESS
// Code To Turn The Fluid One Dispenser
myservo2.attach(3);
// attaches the servo on pin 3 to the servo object
delay(15);
myservo2.write(180);
// sets the servo position according to the scaled value
delay(5000);
// waits 5000ms for it to get to the position
myservo2.detach();
delay(10000);
myservo2.attach(3);
// attaches the servo on pin 3 to the servo object
delay(15);
myservo2.write(-90);
// sets the servo position according to the scaled value
delay(2000); // waits for it to get to the position
myservo2.detach();
delay(10000);
// Step Motor Code Move to Position 3
// WORK IN PROGRESS
// Code To Turn The Fluid Two Dispenser
myservo3.attach(5);
// attaches the servo on pin 5 to the servo object
delay(15);
myservo3.write(180);
// sets the servo position according to the scaled value
delay(5000);
// waits 1000ms for it to get to the position
myservo3.detach();
delay(10000);
myservo3.attach(5);
// attaches the servo on pin 5 to the servo object
delay(15);
myservo3.write(-90);
// sets the servo position according to the scaled value
delay(2000); // waits for it to get to the position
myservo3.detach();
delay(10000);
// Step Motor Code Move to Back To Intial Position (0)
// WORK IN PROGRESS
}