// Adafruit Motor shield library // copyright Adafruit Industries LLC, 2009 // this code is public domain, enjoy! #include // Create motor objects for motors 1 through 4 AF_DCMotor motor1(1); AF_DCMotor motor2(2); AF_DCMotor motor3(3); AF_DCMotor motor4(4); void setup() { Serial.begin(9600); // Start serial communication Serial.println("Motor test!"); // Set initial speed and release all motors motor1.setSpeed(200); motor2.setSpeed(200); motor3.setSpeed(200); motor4.setSpeed(200); motor1.run(RELEASE); motor2.run(RELEASE); motor3.run(RELEASE); motor4.run(RELEASE); } void loop() { uint8_t i; Serial.println("tick"); // Run all motors forward with ramp-up and ramp-down runAllMotors(FORWARD); Serial.println("tock"); // Run all motors backward with ramp-up and ramp-down runAllMotors(BACKWARD); Serial.println("tech"); // Release all motors motor1.run(RELEASE); motor2.run(RELEASE); motor3.run(RELEASE); motor4.run(RELEASE); delay(1000); } // Function to ramp all motors in one direction void runAllMotors(uint8_t direction) { motor1.run(direction); motor2.run(direction); motor3.run(direction); motor4.run(direction); // Ramp speed up for (uint8_t i = 0; i < 255; i++) { motor1.setSpeed(i); motor2.setSpeed(i); motor3.setSpeed(i); motor4.setSpeed(i); delay(10); } // Ramp speed down for (uint8_t i = 255; i != 0; i--) { motor1.setSpeed(i); motor2.setSpeed(i); motor3.setSpeed(i); motor4.setSpeed(i); delay(10); } }