Summary: Demo code for lift team is done.
It will need modifications to the timing values, but here is the finished demo code for the lift mechanism:
It will need modifications to the timing values, but here is the finished demo code for the lift mechanism:
UPDATE: Changed the function set-up:
***********************************
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Motor on M1 and M2
Adafruit_StepperMotor *BMotor = AFMS.getStepper(200, 1);
// Motor on M3 and M4
Adafruit_StepperMotor *FMotor = AFMS.getStepper(200, 2);
//Sets motor directions and speed
int up = FORWARD;
int down = BACKWARD;
int liftSpeed = 50;
int count = 0;
void setup() {
AFMS.begin();
}
void loop() {
liftUp(200);
liftHold(2000);
liftDown(200);
liftHold(2000);
}
//function for lifting, length in steps
void liftUp(int length){
while(count <=
length){
BMotor->setSpeed(liftSpeed);
FMotor->setSpeed(liftSpeed);
BMotor->step(1,up,DOUBLE);
FMotor->step(1,up,DOUBLE);
count++;
}
count = 0;
}
//function for lifting, length in steps
void liftDown(int length){
while(count <=
length){
BMotor->setSpeed(liftSpeed);
FMotor->setSpeed(liftSpeed);
BMotor->step(1,down,DOUBLE);
FMotor->step(1,down,DOUBLE);
count++;
}
count = 0;
}
//function for lifting, length in milliseconds
void liftHold(int length){
delay(length);
}
***********************************
Original:
***********************************
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Motor on M1 and M2
Adafruit_StepperMotor *BMotor = AFMS.getStepper(200, 1);
// Motor on M3 and M4
Adafruit_StepperMotor *FMotor = AFMS.getStepper(200, 2);
int UP = FORWARD;
int DOWN = BACKWARD;
int SPEED = 50;
int count = 0;
void setup() {
AFMS.begin();
}
void loop() {
while(count <= 200){
LiftUp();
count = count + 1;
}
while(count > 200 && count <= 400){
LiftHold();
count = count + 1;
}
while(count > 400 && count <= 600){
LiftDown();
count = count + 1;
}
while(count > 600 && count <= 800){
LiftHold();
count = count + 1;
}
count = 0;
}
void LiftUp(){
BMotor->setSpeed(SPEED);
FMotor->setSpeed(SPEED);
BMotor->step(1,UP,DOUBLE);
FMotor->step(1,UP,DOUBLE);
}
void LiftDown(){
BMotor->setSpeed(SPEED);
FMotor->setSpeed(SPEED);
BMotor->step(1,DOWN,DOUBLE);
FMotor->step(1,DOWN,DOUBLE);
}
void LiftHold(){
delay(10);
}
***********************************
No comments:
Post a Comment