polargraph_arduino/libraries/AFMotor/examples/MotorParty/MotorParty.pde

61 lines
1.2 KiB
Plaintext

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include <AFMotor.h>
#include <ServoTimer1.h>
// DC motor on M2
AF_DCMotor motor(2);
// DC hobby servo
ServoTimer1 servo1;
// Stepper motor on M3+M4 48 steps per revolution
AF_Stepper stepper(48, 2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor party!");
// turn on servo
servo1.attach(9);
// turn on motor #2
motor.setSpeed(200);
motor.run(RELEASE);
}
int i;
// Test the DC motor, stepper and servo ALL AT ONCE!
void loop() {
motor.run(FORWARD);
for (i=0; i<255; i++) {
servo1.write(i);
motor.setSpeed(i);
stepper.step(1, FORWARD, INTERLEAVE);
delay(3);
}
for (i=255; i!=0; i--) {
servo1.write(i-255);
motor.setSpeed(i);
stepper.step(1, BACKWARD, INTERLEAVE);
delay(3);
}
motor.run(BACKWARD);
for (i=0; i<255; i++) {
servo1.write(i);
motor.setSpeed(i);
delay(3);
stepper.step(1, FORWARD, DOUBLE);
}
for (i=255; i!=0; i--) {
servo1.write(i-255);
motor.setSpeed(i);
stepper.step(1, BACKWARD, DOUBLE);
delay(3);
}
}