/* Stepper Motor Control - one revolution This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 - 11 of the Arduino. The motor should revolve one revolution in one direction, then one revolution in the other direction. Created 11 Mar. 2007 Modified 30 Nov. 2009 by Tom Igoe */ #include #include const int stepsPerRevolution =100; // change this to fit the number of steps per revolution // for your motor // initialize the stepper library on pins 8 through 11: Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); Stepper myStepper2(stepsPerRevolution, 2, 3, 4, 5); const int penZUp = 80; const int penZDown = 40; const int penServoPin = 6; Servo penServo; void setup() { // set the speed at 600 rpm: myStepper.setSpeed(100); penServo.attach(6); // initialize the serial port: Serial.begin(9600); } void loop() { Serial.println("left"); for(int stp=0;stp<=260 ;stp++){ myStepper.step(1); myStepper2.step(1); delay(4); } delay(20); penUp(); Serial.println("right"); for(int stp=260;stp>=0 ;stp--){ myStepper.step(-1); myStepper2.step(-1); delay(4); } delay(20); penDown(); } void penUp() { penServo.write(0); delay(150); } void penDown() { penServo.write(40); delay(150); }