Paste Search Dynamic
Recent pastes
Create the motor shield object
  1. #include <Wire.h>
  2. #include <Adafruit_MotorShield.h>
  3.  
  4. // Create the motor shield object with the default I2C address
  5. Adafruit_MotorShield AFMS = Adafruit_MotorShield();
  6. // Or, create it with a different I2C address (say for stacking)
  7. // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
  8.  
  9. // Select which 'port' M1, M2, M3 or M4. In this case, M1
  10. Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
  11. // You can also make another motor on port M2
  12. //Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
  13.  
  14. void setup() {
  15.   Serial.begin(9600);           // set up Serial library at 9600 bps
  16.   Serial.println("Adafruit Motorshield v2 - DC Motor test!");
  17.  
  18.   AFMS.begin();  // create with the default frequency 1.6KHz
  19.   //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  20.  
  21.   // Set the speed to start, from 0 (off) to 255 (max speed)
  22.   myMotor->setSpeed(150);
  23.   myMotor->run(FORWARD);
  24.   // turn on motor
  25.   myMotor->run(RELEASE);
  26. }
  27.  
  28. void loop() {
  29.   uint8_t i;
  30.  
  31.   Serial.print("tick");
  32.  
  33.   myMotor->run(FORWARD);
  34.   for (i=0; i<255; i++) {
  35.     myMotor->setSpeed(i);  
  36.     delay(10);
  37.   }
  38.   for (i=255; i!=0; i--) {
  39.     myMotor->setSpeed(i);  
  40.     delay(10);
  41.   }
  42.  
  43.   Serial.print("tock");
  44.  
  45.   myMotor->run(BACKWARD);
  46.   for (i=0; i<255; i++) {
  47.     myMotor->setSpeed(i);  
  48.     delay(10);
  49.   }
  50.   for (i=255; i!=0; i--) {
  51.     myMotor->setSpeed(i);  
  52.     delay(10);
  53.   }
  54.  
  55.   Serial.print("tech");
  56.   myMotor->run(RELEASE);
  57.   delay(1000);
  58. }
  59.  
Parsed in 0.004 seconds