Enable different modes of stepping by using the settings pins. Previously was causing odd behavior because they were being used for LEDs.

This commit is contained in:
Matt McWilliams 2023-08-29 19:48:49 -04:00
parent d778adc7d0
commit d7a10f9737
3 changed files with 60 additions and 13 deletions

View File

@ -2,9 +2,14 @@
#include "McopyProjector.h"
McopyProjector::McopyProjector (AccelStepper takeup, AccelStepper feed) {
McopyProjector::McopyProjector (AccelStepper takeup, AccelStepper feed, uint8_t takeupSettingA, uint8_t takeupSettingB, uint8_t feedSettingA, uint8_t feedSettingB) {
_takeup = takeup;
_feed = feed;
_takeupSettingA = takeupSettingA;
_takeupSettingB = takeupSettingB;
_feedSettingA = feedSettingA;
_feedSettingB = feedSettingB;
}
void McopyProjector::begin () {
@ -15,6 +20,8 @@ void McopyProjector::begin () {
_feed.setMaxSpeed(_speed);
_feed.setSpeed(_speed);
_feed.setAcceleration(1000.0);
setStepperMode(1);
}
void McopyProjector::setDirection (bool dir) {
@ -80,3 +87,33 @@ void McopyProjector::loop () {
}
}
}
//https://wiki.iteadstudio.com/Arduino_Dual_Step_Motor_Driver_Shield
void McopyProjector::setStepperMode (uint8_t mode) {
switch (mode) {
case 1 :
digitalWrite(_takeupSettingA, LOW);
digitalWrite(_takeupSettingB, LOW);
digitalWrite(_feedSettingA, LOW);
digitalWrite(_feedSettingB, LOW);
break;
case 2 :
digitalWrite(_takeupSettingA, HIGH);
digitalWrite(_takeupSettingB, LOW);
digitalWrite(_feedSettingA, HIGH);
digitalWrite(_feedSettingB, LOW);
break;
case 4 :
digitalWrite(_takeupSettingA, LOW);
digitalWrite(_takeupSettingB, HIGH);
digitalWrite(_feedSettingA, LOW);
digitalWrite(_feedSettingB, HIGH);
break;
case 8 :
digitalWrite(_takeupSettingA, HIGH);
digitalWrite(_takeupSettingB, HIGH);
digitalWrite(_feedSettingA, HIGH);
digitalWrite(_feedSettingB, HIGH);
break;
}
}

View File

@ -13,17 +13,17 @@ class McopyProjector {
uint8_t _motorSteps = 1600; //microstepped
uint8_t _frames = 8;
uint8_t _stepsPerFrame = 25; //round(_motorSteps / _frames);
uint8_t _stepsPerFrame = 50; //round(_motorSteps / _frames);
float _speed = 500.0;
int64_t _posTakeup = 0;
int64_t _posFeed = 0;
const uint8_t FORWARD = 1; //CW
const uint8_t BACKWARD = 0; //CCW
const uint8_t TAKEUP = 0;
const uint8_t FEED = 0;
uint8_t _takeupSettingA = 4;
uint8_t _takeupSettingB = 5;
uint8_t _feedSettingA = 8;
uint8_t _feedSettingB = 9;
bool _dir = true;
@ -32,7 +32,7 @@ class McopyProjector {
public:
McopyProjector(AccelStepper takeup, AccelStepper feed);
McopyProjector(AccelStepper takeup, AccelStepper feed, uint8_t takeupSettingA, uint8_t takeupSettingB, uint8_t feedSettingA, uint8_t feedSettingB);
void begin();
//0 = takeup, 1 = feed
void adjust(uint8_t motor, int64_t steps);
@ -40,6 +40,7 @@ class McopyProjector {
//true = forward, false = back
void frame(bool dir);
void setDirection(bool dir);
void setStepperMode(uint8_t mode);
void loop();
};

View File

@ -31,16 +31,20 @@
#define FEED_DIR_PIN 7
#define FEED_STEP_PIN 6
#define TAKEUP_SETTING_A 4
#define TAKEUP_SETTING_B 5
#define FEED_SETTING_A 8
#define FEED_SETTING_B 9
AccelStepper takeup(AccelStepper::DRIVER, TAKEUP_STEP_PIN, TAKEUP_DIR_PIN);
AccelStepper feed(AccelStepper::DRIVER, FEED_STEP_PIN, FEED_DIR_PIN);
//CAMERA CONSTANTS
const int BUTTON = 7;
const int LED_FWD = 8;
const int LED_BWD = 9;
//PROJECTOR CONSTANTS
const int BUTTON = 10;
const int LED_FWD = 11;
const int LED_BWD = 12;
const int PROJECTOR_MOMENT = 240;
const int PROJECTOR_STEPS = 25;
//VARIABLES
volatile int projectorFrame = -1;
@ -50,7 +54,7 @@ volatile bool direction = true;
volatile long start;
McopySerial mcopy;
McopyProjector projector(takeup, feed);
McopyProjector projector(takeup, feed, TAKEUP_SETTING_A, TAKEUP_SETTING_B, FEED_SETTING_A, FEED_SETTING_B);
void setup () {
pins();
@ -78,6 +82,11 @@ void pins () {
pinMode(LED_BWD, OUTPUT);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(TAKEUP_SETTING_A, OUTPUT);
pinMode(TAKEUP_SETTING_B, OUTPUT);
pinMode(FEED_SETTING_A, OUTPUT);
pinMode(FEED_SETTING_B, OUTPUT);
digitalWrite(LED_FWD, LOW);
digitalWrite(LED_BWD, LOW);
}