I've written a sketch using the Adafruit motor shield to take a picture, move a mirror at constant stepper speed 296 steps, take a 2nd picture, and return. I'd like to have the mirror accelerate and deaccelerate instead of running at constant speed so I can get it in position more quickly. I've read and tried all of the AccelStepper examples but I can't figure out how to just do a single accel/deaccel movement followed by other code followed by another movement.
Also I have a bipolar motor and I think the AccelStepper code defaults to unipolar and I can't figure out I tell it my motor is bipolar??
Here is my code and I would like to just replace the current motor movement with AccelStepper code. Are there examples I can copy? Where would I find them?
#include <AFMotor.h>
AF_Stepper motor(400, 2);//400 steps per rev, port 2 M3-M4
byte camtrig=13;//set output 13 to trigger camera
int prepulse=125;
int campulse=55;
int picdelay=215;
int flipdelay=50;//delay pic1 to start flip
float rate=1;//multiplier for speed of machine
byte mirrorPos=0;//flag for mirror position
byte button=2;//button to trigger cycle
int sensor=1;// flip mirror sensor
int delta=14;// mirror adj to home position
void setup() {
Serial.begin(9600);// set up Serial library at 9600 bps
Serial.flush();//clear serial line
motor.release();//motor off
pinMode(button,INPUT);
digitalWrite(button,LOW);
pinMode(camtrig,OUTPUT); //set pin 13 as output
motor.setSpeed(20);//motor speed at initialize
}
void loop(){
// check if button is pressed
byte state2 = digitalRead(button);
if (state2 == HIGH ) {
// Call the function pic flip and pic
PicFlipPic();}}
void PicFlipPic(){
//Take pic1
digitalWrite(camtrig,HIGH);//pretrigger 1
delay(prepulse);
digitalWrite(camtrig,LOW);
delay(picdelay);
digitalWrite(camtrig,HIGH);//picture 1
delay(campulse);
digitalWrite(camtrig,LOW);
delay(flipdelay);
//End pic1
motor.setSpeed(80); //80 rpm
motor.step(296, BACKWARD, DOUBLE);//#steps, direction, steptype
mirrorPos=2;
//Take pic2
digitalWrite(camtrig,HIGH);//pretrigger 2
delay(prepulse);
digitalWrite(camtrig,LOW);
delay(picdelay);
digitalWrite(camtrig,HIGH);//picture 2
delay(campulse);
digitalWrite(camtrig,LOW);
delay(flipdelay);
//End pic2
motor.setSpeed(40); //40 rpm
motor.step(296, FORWARD, SINGLE);
mirrorPos=1;
delay (1000);
}