Hello,
I am hoping this is not redundant; I am trying to actuate a few linear actuators IN A SEQUENTIAL manner.
I am using motor shield v2 and arduino mega 2560 with firgelli L12 -P.
I am using the following:
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
Adafruit_DCMotor *yourMotor = AFMS.getMotor(3);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(100);
myOtherMotor->setSpeed(100);
yourMotor->setSpeed(100);
myMotor->run(FORWARD);
myOtherMotor->run(FORWARD);
yourMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);
myOtherMotor->run(RELEASE);
yourMotor->run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
myMotor->run(FORWARD);
// delay();
myOtherMotor->run(FORWARD);
// delay();
yourMotor->run(FORWARD);
for (i=0; i<255; i++) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
yourMotor->setSpeed(i);
delay(750);
}
for (i=255; i!=0; i--) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
yourMotor->setSpeed(i);
delay(750);
}
Serial.print("tock");
myMotor->run(BACKWARD);
myOtherMotor->run(BACKWARD);
yourMotor->run(BACKWARD);
for (i=0; i<255; i++) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
yourMotor->setSpeed(i);
delay(750);
}
for (i=255; i!=0; i--) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
yourMotor->setSpeed(i);
delay(750);
}
Serial.print("tech");
myMotor->run(RELEASE);
myOtherMotor->run(RELEASE);
yourMotor->run(RELEASE);
delay(100);
}
I am not sure where to put the delays (or not sure if putting delay is conventional when trying to make sequence of motions!?
any help would be appreciated very much! This does not seem to be so difficult but I am not getting the kind of motion I want.,
Regards,
Karim.