2023-05-25 14:43:45 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
JK-compatible projector element
|
|
|
|
|
|
|
|
Hardware
|
|
|
|
|
|
|
|
Arduino Uno
|
|
|
|
Itead Dual Stepper Shield
|
|
|
|
2x NEMA17 Stepper Motors
|
|
|
|
|
|
|
|
Wiring
|
|
|
|
|
|
|
|
(Will vary from motor to motor)
|
|
|
|
X01A - Green
|
|
|
|
X01B - Black
|
|
|
|
X02A - Blue
|
|
|
|
X02B - Red
|
|
|
|
|
|
|
|
Y01A - Green
|
|
|
|
Y01B - Black
|
|
|
|
Y02A - Blue
|
|
|
|
Y02B - Red
|
|
|
|
*/
|
2023-08-23 19:21:50 +00:00
|
|
|
#include "McopyProjector.h"
|
2023-05-25 14:43:45 +00:00
|
|
|
#include "McopySerial.h"
|
|
|
|
#include "IteadDualStepperShield.h"
|
|
|
|
|
2023-08-23 19:21:50 +00:00
|
|
|
|
2023-05-25 14:43:45 +00:00
|
|
|
//CAMERA CONSTANTS
|
|
|
|
const int BUTTON = 7;
|
|
|
|
const int LED_FWD = 8;
|
|
|
|
const int LED_BWD = 9;
|
|
|
|
|
|
|
|
const int PROJECTOR_MOMENT = 240;
|
|
|
|
const int PROJECTOR_STEPS = 25;
|
|
|
|
|
|
|
|
//VARIABLES
|
|
|
|
volatile int projectorFrame = -1;
|
|
|
|
volatile char cmdChar = 'z';
|
|
|
|
volatile long now;
|
|
|
|
volatile bool direction = true;
|
|
|
|
volatile long start;
|
|
|
|
|
|
|
|
McopySerial mcopy;
|
2023-08-23 19:21:50 +00:00
|
|
|
McopyProjector projector;
|
2023-05-25 14:43:45 +00:00
|
|
|
|
|
|
|
void setup () {
|
2023-08-23 19:21:50 +00:00
|
|
|
|
2023-05-25 14:43:45 +00:00
|
|
|
|
|
|
|
pins();
|
|
|
|
digitalWrite(LED_FWD, HIGH);
|
|
|
|
digitalWrite(LED_BWD, HIGH);
|
|
|
|
mcopy.begin(mcopy.PROJECTOR_IDENTIFIER);
|
2023-08-23 19:21:50 +00:00
|
|
|
projector.begin();
|
2023-05-25 14:43:45 +00:00
|
|
|
delay(42);
|
|
|
|
digitalWrite(LED_FWD, LOW);
|
|
|
|
digitalWrite(LED_BWD, LOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop () {
|
|
|
|
now = millis();
|
|
|
|
cmdChar = mcopy.loop();
|
|
|
|
cmd(cmdChar);
|
|
|
|
if (digitalRead(BUTTON) == LOW) {
|
2023-08-23 19:21:50 +00:00
|
|
|
projector_frame();
|
2023-05-25 14:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pins () {
|
|
|
|
pinMode(LED_FWD, OUTPUT);
|
|
|
|
pinMode(LED_BWD, OUTPUT);
|
|
|
|
pinMode(BUTTON, INPUT_PULLUP);
|
|
|
|
|
|
|
|
digitalWrite(LED_FWD, LOW);
|
|
|
|
digitalWrite(LED_BWD, LOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd (char val) {
|
2023-08-23 19:21:50 +00:00
|
|
|
if (val == mcopy.PROJECTOR_FORWARD) {
|
2023-05-25 14:43:45 +00:00
|
|
|
projector_direction(true);
|
2023-08-23 19:21:50 +00:00
|
|
|
} else if (val == mcopy.PROJECTOR_BACKWARD) {
|
2023-05-25 14:43:45 +00:00
|
|
|
projector_direction(false);
|
|
|
|
} else if (val == mcopy.PROJECTOR) {
|
2023-08-23 19:21:50 +00:00
|
|
|
projector_frame();
|
2023-05-25 14:43:45 +00:00
|
|
|
} else if (val == mcopy.STATE) {
|
|
|
|
state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void projector_direction (boolean state) {
|
|
|
|
direction = state;
|
|
|
|
if (state) {
|
|
|
|
mcopy.confirm(mcopy.PROJECTOR_FORWARD);
|
|
|
|
mcopy.log("projector_direction(true)");
|
2023-08-23 19:21:50 +00:00
|
|
|
projector.setDirection(true);
|
2023-05-25 14:43:45 +00:00
|
|
|
} else {
|
|
|
|
mcopy.confirm(mcopy.PROJECTOR_BACKWARD);
|
|
|
|
mcopy.log("projector_direction(false)");
|
2023-08-23 19:21:50 +00:00
|
|
|
projector.setDirection(false);
|
2023-05-25 14:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void projector_timing_start () {
|
|
|
|
start = millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
void projector_timing_end () {
|
|
|
|
long end = millis();
|
|
|
|
if (projectorFrame == -1) {
|
|
|
|
projectorFrame = (end - start);
|
|
|
|
} else {
|
|
|
|
//rolling mean
|
|
|
|
projectorFrame = (projectorFrame + (end - start) / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 19:21:50 +00:00
|
|
|
void projector_frame () {
|
2023-05-25 14:43:45 +00:00
|
|
|
int LED = direction ? LED_FWD : LED_BWD;
|
|
|
|
digitalWrite(LED, HIGH);
|
2023-08-23 19:21:50 +00:00
|
|
|
projector.frame(direction);
|
2023-05-25 14:43:45 +00:00
|
|
|
mcopy.confirm(mcopy.PROJECTOR);
|
|
|
|
digitalWrite(LED, LOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void state () {
|
|
|
|
String stateString = String(mcopy.CAMERA_EXPOSURE);
|
2023-05-25 14:45:44 +00:00
|
|
|
stateString += String(projectorFrame);
|
2023-05-25 14:43:45 +00:00
|
|
|
stateString += String(mcopy.STATE);
|
|
|
|
mcopy.print(stateString);
|
|
|
|
}
|