#include // Define pin connections & motor's steps per revolution const int dirPin = 2; const int stepPin = 3; const int servoPin = 9; const int stepsPerRevolution = 800; Servo myservo; int pos = 0; void setup() { // Declare pins as Outputs pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); myservo.attach(servoPin); } void loop() { // Set motor direction clockwise digitalWrite(dirPin, HIGH); // Spin stepper motor for(int x = 0; x < stepsPerRevolution; x++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); digitalWrite(stepPin, LOW); delayMicroseconds(1000); } // Rotate servo motor for (pos = 0; pos <= 90; pos += 1) { myservo.write(pos); delay(10); } delay(2000); for (pos = 90; pos >= 0; pos -= 1) { myservo.write(pos); delay(10); } // Set motor direction counterclockwise digitalWrite(dirPin, LOW); // Spin motor quickly for(int x = 0; x < stepsPerRevolution; x++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); digitalWrite(stepPin, LOW); delayMicroseconds(1000); } delay(1000); }