2023-08-23 19:21:50 +00:00
|
|
|
#ifndef MCOPY_PROJECTOR
|
|
|
|
#define MCOPY_PROJECTOR
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2023-08-29 19:33:51 +00:00
|
|
|
#include <AccelStepper.h>
|
2023-10-09 13:59:19 +00:00
|
|
|
#include <Servo.h>
|
2023-08-23 19:21:50 +00:00
|
|
|
|
2023-08-30 05:18:10 +00:00
|
|
|
/**
|
|
|
|
* D2 X Step
|
|
|
|
* D3 X Direction
|
|
|
|
* D4 X MS1 setting
|
|
|
|
* D5 X MS2 setting
|
|
|
|
* D6 Y Step
|
|
|
|
* D7 Y Direction
|
|
|
|
* D8 Y MS1 setting
|
|
|
|
* D9 Y MS2 setting
|
|
|
|
*
|
|
|
|
* MS1(X/Y) MS2(X/Y) Description
|
|
|
|
* L L Full step
|
|
|
|
* H L Half step
|
|
|
|
* L H Quarter step
|
|
|
|
* H H Eighth STEP
|
|
|
|
**/
|
|
|
|
|
2023-08-23 19:21:50 +00:00
|
|
|
class McopyProjector {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2023-08-29 19:33:51 +00:00
|
|
|
AccelStepper _takeup;
|
|
|
|
AccelStepper _feed;
|
2023-08-23 19:21:50 +00:00
|
|
|
|
2023-10-09 13:59:19 +00:00
|
|
|
Servo _servo;
|
|
|
|
|
2023-09-26 01:54:31 +00:00
|
|
|
const uint16_t _motorSteps = 200; //full steps
|
|
|
|
const uint8_t _frames = 8;
|
|
|
|
const uint16_t _stepsPerFrame = 25; //round(_motorSteps / _frames);
|
|
|
|
const float _speed = 2000.0;
|
|
|
|
|
2023-10-09 13:59:19 +00:00
|
|
|
const uint8_t _servoHome = 90;
|
|
|
|
const uint8_t _servoAway = 60;
|
|
|
|
|
2023-09-26 01:54:31 +00:00
|
|
|
volatile uint8_t _mode = 1;
|
2023-08-23 19:21:50 +00:00
|
|
|
|
|
|
|
int64_t _posTakeup = 0;
|
|
|
|
int64_t _posFeed = 0;
|
2023-10-10 02:58:48 +00:00
|
|
|
//Y
|
2023-09-26 01:54:31 +00:00
|
|
|
uint8_t _takeupSettingA;
|
|
|
|
uint8_t _takeupSettingB;
|
2023-10-10 02:58:48 +00:00
|
|
|
//X
|
2023-09-26 01:54:31 +00:00
|
|
|
uint8_t _feedSettingA;
|
|
|
|
uint8_t _feedSettingB;
|
2023-10-10 02:58:48 +00:00
|
|
|
//Y
|
2023-09-26 01:54:31 +00:00
|
|
|
uint8_t _takeupEmitter;
|
|
|
|
uint8_t _takeupReceiver;
|
2023-10-10 02:58:48 +00:00
|
|
|
//X
|
2023-09-26 01:54:31 +00:00
|
|
|
uint8_t _feedEmitter;
|
|
|
|
uint8_t _feedReceiver;
|
|
|
|
|
2023-10-09 13:59:19 +00:00
|
|
|
uint8_t _servoPin;
|
|
|
|
|
2023-09-26 01:54:31 +00:00
|
|
|
long _feedSamples[200];
|
|
|
|
long _takeupSamples[200];
|
2023-08-25 20:44:28 +00:00
|
|
|
|
2023-08-23 19:21:50 +00:00
|
|
|
bool _dir = true;
|
|
|
|
|
2023-08-29 19:33:51 +00:00
|
|
|
bool _running = false;
|
|
|
|
bool _adjusting = false;
|
|
|
|
|
2023-09-22 01:06:31 +00:00
|
|
|
long readVcc();
|
2023-09-26 01:54:31 +00:00
|
|
|
long analogReadAccurate (uint8_t &pin);
|
|
|
|
long analogReadAccurateAverage (uint8_t &pin);
|
|
|
|
uint16_t findPeak(long (&arr)[200], uint16_t &steps);
|
2023-10-03 17:44:04 +00:00
|
|
|
void emitters(bool enabled);
|
2023-09-22 01:06:31 +00:00
|
|
|
|
2023-08-23 19:21:50 +00:00
|
|
|
public:
|
|
|
|
|
2023-09-26 01:54:31 +00:00
|
|
|
McopyProjector(AccelStepper takeup, AccelStepper feed,
|
|
|
|
uint8_t takeupSettingA, uint8_t takeupSettingB,
|
|
|
|
uint8_t feedSettingA, uint8_t feedSettingB,
|
|
|
|
uint8_t takeupEmitter, uint8_t takeupReceiver,
|
2023-10-09 13:59:19 +00:00
|
|
|
uint8_t feedEmitter, uint8_t feedReceiver,
|
|
|
|
uint8_t servoPin);
|
2023-08-23 19:21:50 +00:00
|
|
|
void begin();
|
|
|
|
//0 = takeup, 1 = feed
|
2023-08-25 20:44:28 +00:00
|
|
|
void adjust(uint8_t motor, int64_t steps);
|
|
|
|
void adjustBoth(int64_t steps);
|
2023-08-23 19:21:50 +00:00
|
|
|
//true = forward, false = back
|
|
|
|
void frame(bool dir);
|
|
|
|
void setDirection(bool dir);
|
2023-08-29 23:48:49 +00:00
|
|
|
void setStepperMode(uint8_t mode);
|
2023-08-29 19:33:51 +00:00
|
|
|
void loop();
|
2023-09-22 01:06:31 +00:00
|
|
|
void home();
|
2023-09-26 01:54:31 +00:00
|
|
|
void firstPass();
|
|
|
|
void centerPass();
|
2023-09-22 01:06:31 +00:00
|
|
|
|
2023-08-23 19:21:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|