2018-01-05 20:49:19 +00:00
|
|
|
/*
|
|
|
|
Wiring
|
|
|
|
|
2018-01-23 03:05:05 +00:00
|
|
|
HOLD OFF FOR NOW
|
2018-01-05 20:49:19 +00:00
|
|
|
For "MONITOR" pins with INPUT_PULLUP resistors:
|
|
|
|
GND-----\ | \-----PIN
|
|
|
|
No additional resistors/caps needed.
|
2018-01-17 17:23:23 +00:00
|
|
|
--Note: not needed in prototype
|
|
|
|
|
2018-01-05 20:49:19 +00:00
|
|
|
|
|
|
|
CAMERA + CAMERA_DIR and PROJECTOR + PROJECTOR_DIR:
|
|
|
|
Wire directly to corresponding relay pins.
|
|
|
|
Arduino 2 3 8 9
|
|
|
|
Relay 1 2 3 4
|
|
|
|
*/
|
|
|
|
|
|
|
|
boolean debug_state = false;
|
|
|
|
|
2018-01-17 17:23:23 +00:00
|
|
|
//unsigned long now; //to be compared to stored values every loop
|
2018-01-05 20:49:19 +00:00
|
|
|
|
2018-01-17 17:23:23 +00:00
|
|
|
//CAMERA CONSTANTS
|
2018-01-05 20:49:19 +00:00
|
|
|
const int CAMERA = 2;
|
2018-01-23 03:05:05 +00:00
|
|
|
const int CAMERA_FWD = 3;
|
|
|
|
const int CAMERA_BWD = 4;
|
2018-01-30 10:05:04 +00:00
|
|
|
const int CAMERA_MOMENT = 240;
|
|
|
|
const int CAMERA_FRAME = 600;
|
2018-01-17 17:23:23 +00:00
|
|
|
//CAMERA VARIABLES
|
2018-01-05 20:49:19 +00:00
|
|
|
boolean cam_dir = true;
|
|
|
|
|
2018-01-17 17:23:23 +00:00
|
|
|
//PROJECTOR CONSTANTS
|
2018-01-05 20:49:19 +00:00
|
|
|
const int PROJECTOR = 8;
|
2018-01-23 03:05:05 +00:00
|
|
|
const int PROJECTOR_FWD = 9;
|
|
|
|
const int PROJECTOR_BWD = 10;
|
2018-07-03 18:25:36 +00:00
|
|
|
const int PROJECTOR_MOMENT = 200;
|
2018-01-30 10:05:04 +00:00
|
|
|
const int PROJECTOR_FRAME = 950;
|
2018-01-17 17:23:23 +00:00
|
|
|
//PROJECTOR VARIABLES
|
2018-01-05 20:49:19 +00:00
|
|
|
boolean proj_dir = true;
|
|
|
|
|
|
|
|
//PROJECTOR COMMANDS
|
|
|
|
const char cmd_projector = 'p';
|
|
|
|
const char cmd_proj_forward = 'g';
|
|
|
|
const char cmd_proj_backward = 'h';
|
|
|
|
|
|
|
|
//CAMERA COMMANDS
|
|
|
|
const char cmd_camera = 'c';
|
|
|
|
const char cmd_cam_forward = 'e';
|
|
|
|
const char cmd_cam_backward = 'f';
|
|
|
|
|
|
|
|
const char cmd_debug = 'd';
|
|
|
|
const char cmd_connect = 'i';
|
|
|
|
volatile char cmd_char = 'z';
|
|
|
|
const char cmd_mcopy_identifier = 'm';
|
|
|
|
|
|
|
|
//const char cmd_proj_identifier = 'j';
|
|
|
|
const char cmd_proj_cam_identifier = 's';
|
|
|
|
|
|
|
|
const int serialDelay = 5;
|
|
|
|
|
|
|
|
void setup () {
|
|
|
|
Serial.begin(57600);
|
|
|
|
Serial.flush();
|
2018-01-17 17:23:23 +00:00
|
|
|
//Serial.setTimeout(serialDelay);
|
2018-01-05 20:49:19 +00:00
|
|
|
|
|
|
|
pins();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop () {
|
2018-01-17 17:23:23 +00:00
|
|
|
//now = millis();
|
2018-01-05 20:49:19 +00:00
|
|
|
if (Serial.available()) {
|
|
|
|
/* read the most recent byte */
|
|
|
|
cmd_char = (char)Serial.read();
|
|
|
|
}
|
|
|
|
if (cmd_char != 'z') {
|
|
|
|
cmd(cmd_char);
|
|
|
|
cmd_char = 'z';
|
|
|
|
}
|
|
|
|
|
2018-01-17 17:23:23 +00:00
|
|
|
/*delay(2000);
|
|
|
|
cam_start();
|
|
|
|
delay(2000);
|
|
|
|
proj_start();*/
|
2018-01-05 20:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pins () {
|
|
|
|
//RELAYS
|
|
|
|
pinMode(CAMERA, OUTPUT);
|
|
|
|
pinMode(PROJECTOR, OUTPUT);
|
|
|
|
|
2018-01-23 03:05:05 +00:00
|
|
|
pinMode(CAMERA_FWD, OUTPUT);
|
|
|
|
pinMode(CAMERA_BWD, OUTPUT);
|
|
|
|
pinMode(PROJECTOR_FWD, OUTPUT);
|
|
|
|
pinMode(PROJECTOR_BWD, OUTPUT);
|
2018-01-05 20:49:19 +00:00
|
|
|
|
|
|
|
//SET LOW
|
|
|
|
digitalWrite(CAMERA, LOW);
|
|
|
|
digitalWrite(PROJECTOR, LOW);
|
2018-01-23 03:05:05 +00:00
|
|
|
|
|
|
|
digitalWrite(CAMERA_FWD, HIGH);
|
|
|
|
digitalWrite(CAMERA_BWD, LOW);
|
|
|
|
|
|
|
|
digitalWrite(PROJECTOR_FWD, HIGH);
|
|
|
|
digitalWrite(PROJECTOR_BWD, LOW);
|
2018-01-05 20:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmd (char val) {
|
|
|
|
if (val == cmd_debug) {
|
|
|
|
debug();
|
|
|
|
} else if (val == cmd_connect) {
|
|
|
|
connect();
|
|
|
|
} else if (val == cmd_mcopy_identifier) {
|
|
|
|
identify();
|
|
|
|
} else if (val == cmd_projector) {
|
|
|
|
proj_start();
|
|
|
|
} else if (val == cmd_proj_forward) {
|
|
|
|
proj_direction(true);
|
|
|
|
} else if (val == cmd_proj_backward) {
|
|
|
|
proj_direction(false);
|
|
|
|
} else if (val == cmd_cam_forward) {
|
|
|
|
cam_direction(true); //explicit
|
|
|
|
} else if (val == cmd_cam_backward) {
|
|
|
|
cam_direction(false);
|
|
|
|
} else if (val == cmd_camera) {
|
|
|
|
cam_start();
|
|
|
|
}
|
2018-01-05 04:45:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 20:49:19 +00:00
|
|
|
void debug () {
|
|
|
|
debug_state = true;
|
|
|
|
Serial.println(cmd_debug);
|
|
|
|
log("debugging enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
void connect () {
|
|
|
|
Serial.println(cmd_connect);
|
|
|
|
log("connect()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void identify () {
|
|
|
|
Serial.println(cmd_proj_cam_identifier);
|
|
|
|
log("identify()");
|
|
|
|
}
|
|
|
|
|
2018-01-17 17:23:23 +00:00
|
|
|
void setDir (int pin, boolean dir) {
|
|
|
|
if (!dir) {
|
|
|
|
digitalWrite(pin, HIGH);
|
|
|
|
} else {
|
|
|
|
digitalWrite(pin, LOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 20:49:19 +00:00
|
|
|
void proj_start () {
|
|
|
|
digitalWrite(PROJECTOR, HIGH);
|
2018-01-17 17:23:23 +00:00
|
|
|
delay(PROJECTOR_MOMENT);
|
|
|
|
digitalWrite(PROJECTOR, LOW);
|
2018-01-30 10:05:04 +00:00
|
|
|
delay(PROJECTOR_FRAME - PROJECTOR_MOMENT);
|
2018-01-17 17:23:23 +00:00
|
|
|
proj_stop();
|
2018-01-05 20:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cam_start () {
|
|
|
|
digitalWrite(CAMERA, HIGH);
|
2018-01-17 17:23:23 +00:00
|
|
|
delay(CAMERA_MOMENT);
|
|
|
|
digitalWrite(CAMERA, LOW);
|
2018-01-30 10:05:04 +00:00
|
|
|
delay(CAMERA_FRAME - CAMERA_MOMENT);
|
2018-01-17 17:23:23 +00:00
|
|
|
cam_stop();
|
2018-01-05 20:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void proj_stop () {
|
|
|
|
Serial.println(cmd_projector);
|
|
|
|
log("projector()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void cam_stop () {
|
|
|
|
Serial.println(cmd_camera);
|
|
|
|
log("camera()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void proj_direction (boolean state) {
|
|
|
|
proj_dir = state;
|
|
|
|
if (state) {
|
2018-01-23 03:05:05 +00:00
|
|
|
digitalWrite(PROJECTOR_BWD, LOW);
|
|
|
|
delay(10);
|
|
|
|
digitalWrite(PROJECTOR_FWD, HIGH);
|
2018-01-05 20:49:19 +00:00
|
|
|
Serial.println(cmd_proj_forward);
|
|
|
|
log("proj_direction -> true");
|
|
|
|
} else {
|
2018-01-23 03:05:05 +00:00
|
|
|
digitalWrite(PROJECTOR_FWD, LOW);
|
|
|
|
delay(10);
|
|
|
|
digitalWrite(PROJECTOR_BWD, HIGH);
|
2018-01-05 20:49:19 +00:00
|
|
|
Serial.println(cmd_proj_backward);
|
|
|
|
log("proj_direction -> false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cam_direction (boolean state) {
|
|
|
|
cam_dir = state;
|
|
|
|
if (state) {
|
2018-01-23 03:05:05 +00:00
|
|
|
digitalWrite(CAMERA_BWD, LOW);
|
|
|
|
delay(10);
|
|
|
|
digitalWrite(CAMERA_FWD, HIGH);
|
2018-01-05 20:49:19 +00:00
|
|
|
Serial.println(cmd_cam_forward);
|
|
|
|
log("cam_direction -> true");
|
|
|
|
} else {
|
2018-01-23 03:05:05 +00:00
|
|
|
digitalWrite(CAMERA_FWD, LOW);
|
|
|
|
delay(10);
|
|
|
|
digitalWrite(CAMERA_BWD, HIGH);
|
2018-01-05 20:49:19 +00:00
|
|
|
Serial.println(cmd_cam_backward);
|
|
|
|
log("cam_direction -> false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log (String msg) {
|
|
|
|
if (debug_state) {
|
|
|
|
Serial.println(msg);
|
|
|
|
}
|
2018-01-17 17:23:23 +00:00
|
|
|
}
|
|
|
|
|