From f276d5ce83983703c439e3f0df31fa2fae64ee16 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 1 Mar 2019 20:14:20 -0500 Subject: [PATCH] Add commands for controlling a secondary projector. --- app/data/cfg.json | 7 +- .../mcopy_mono_firmware_camera.ino | 2 +- .../mcopy_mono_firmware_projectors.ino | 162 +++++++++++++++--- ...opy_mono_firmware_projectors_secondary.ino | 2 +- 4 files changed, 148 insertions(+), 25 deletions(-) diff --git a/app/data/cfg.json b/app/data/cfg.json index d726a0f..45362b8 100644 --- a/app/data/cfg.json +++ b/app/data/cfg.json @@ -118,7 +118,12 @@ "proj_light_identifier" : "q", "proj_cam_light_identifier" : "r", "proj_cam_identifier" : "s", - "proj_second_identifier" : "t" + "proj_second_identifier" : "t", + "proj_dual_identifier" : "d", + "proj_second_forward" : "u", + "proj_second_backward" : "v", + "projector_second" : "w", + "projectors" : "x" } } } \ No newline at end of file diff --git a/ino/mcopy_mono_firmware_camera/mcopy_mono_firmware_camera.ino b/ino/mcopy_mono_firmware_camera/mcopy_mono_firmware_camera.ino index 4b11c5a..fdd108b 100644 --- a/ino/mcopy_mono_firmware_camera/mcopy_mono_firmware_camera.ino +++ b/ino/mcopy_mono_firmware_camera/mcopy_mono_firmware_camera.ino @@ -1,6 +1,6 @@ /** * This is a specialized version of the mcopy firmware for - * controlling the camera of the optical printer + * controlling the BBOptics Mitchel camera of the optical printer * at MONO NO AWARE. This uses a Sainsmart 4 Relay Module * board wired into the directional switches and "indiv" trigger * switch of a JK104-R camera controller box, and it runs on an diff --git a/ino/mcopy_mono_firmware_projectors/mcopy_mono_firmware_projectors.ino b/ino/mcopy_mono_firmware_projectors/mcopy_mono_firmware_projectors.ino index 732fc0d..30434e5 100644 --- a/ino/mcopy_mono_firmware_projectors/mcopy_mono_firmware_projectors.ino +++ b/ino/mcopy_mono_firmware_projectors/mcopy_mono_firmware_projectors.ino @@ -4,39 +4,61 @@ * at MONO NO AWARE. This uses a Sainsmart 8 Solid State Relay * board wired into the directional switches of a JK104-R projector * controller box, a secondary projector controller box and it - * runs on an Arduino Uno compatible board. + * runs on an Arduino Mega 1280 compatible board. * - * Pins - * 12 - CH1 - FWD - * 11 - CH2 - BWD (bridged to CH1) - * - controls the directional relays of the secondary projector. - * 10 - CH3 - 4 pronged trigger cable - * - triggers the secondary projector + * Pins - 8CH Sainsmart Solid State Relay Board + * 12 - CH1 - BWD PROJ 1 + * 11 - CH2 - FWD PROJ 1 (bridged to CH1) + * 10 - CH3 - BWD PROJ 1 + * 09 - CH4 - FWD PROJ 1 (bridged to CH3) + * 08 - CH5 - BWD PROJ 1 + * - controls the directional relays of the primary projector. + * 07 - CH8 - 4 pronged trigger cable + * - triggers the primary projectory */ - boolean debug_state = false; -const int proj_fwd_pin = 12; -const int proj_bwd_pin = 11; -const int proj_pin = 10; +const int proj_bwd_pin_1 = 12; +const int proj_fwd_pin_1 = 11; +const int proj_bwd_pin_2 = 10; +const int proj_fwd_pin_2 = 9; +const int proj_bwd_pin_3 = 8; +const int proj_pin = 7; + +const int proj_second_fwd_pin = 6; +const int proj_second_bwd_pin = 5; +const int proj_second_pin = 4; const int proj_momentary = 60; const int proj_time = 950; //secondary projector speed const int proj_delay = 42; +const int proj_second_momentary = 60; +const int proj_second_time = 950; //adjust +const int proj_second_delay = 42; //use same + boolean proj_dir = true; boolean proj_running = false; +boolean proj_second_dir = true; +boolean proj_second_running = false; + const char cmd_projector = 'p'; const char cmd_proj_forward = 'g'; const char cmd_proj_backward = 'h'; +const char cmd_proj_second_forward = 'u'; +const char cmd_proj_second_backward = 'v'; +const char cmd_projector_second = 'w'; + +const char cmd_projectors = 'x'; + 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_identifier = 'j'; //'d'; //dual projector identifier const int serialDelay = 5; @@ -44,13 +66,8 @@ void setup() { Serial.begin(57600); Serial.flush(); Serial.setTimeout(serialDelay); - pinMode(proj_fwd_pin, OUTPUT); - pinMode(proj_bwd_pin, OUTPUT); - pinMode(proj_pin, OUTPUT); - digitalWrite(proj_pin, LOW); - digitalWrite(proj_fwd_pin, HIGH); - digitalWrite(proj_bwd_pin, LOW); + Pins_init(); } void loop() { @@ -77,6 +94,14 @@ void cmd (char val) { proj_direction(true); } else if (val == cmd_proj_backward) { proj_direction(false); + } else if (val == cmd_proj_second_forward) { + proj_second_direction(true); + } else if (val == cmd_proj_second_backward) { + proj_second_direction(false); + } else if (val == cmd_projector_second) { + projector_second(); + } else if (val == cmd_projectors) { + projectors(); } } @@ -113,22 +138,115 @@ void projector () { } } +void projector_second () { + if (!proj_second_running) { + proj_second_running = true; + digitalWrite(proj_second_pin, HIGH); + + delay(proj_second_momentary); + digitalWrite(proj_second_pin, LOW); + + delay(proj_second_time - proj_second_momentary + proj_second_delay); + + Serial.println(cmd_projector_second); + log("projector_second()"); + proj_second_running = false; + } +} + +void projectors () { + int proj_time_highest = proj_time; + if (!proj_running && !proj_second_running) { + if (proj_second_time > proj_time) { + proj_time_highest = proj_second_time; + } + proj_running = true; + proj_second_running = true; + + digitalWrite(proj_pin, HIGH); + digitalWrite(proj_second_pin, HIGH); + delay(proj_momentary); //highest? they are the same + digitalWrite(proj_pin, LOW); + digitalWrite(proj_second_pin, LOW); + + delay(proj_time_highest - proj_momentary + proj_delay); + + Serial.println(cmd_projectors); //cmd_projectors + log("projectors()"); + proj_running = false; + proj_second_running = false; + } +} + void proj_direction (boolean state) { proj_dir = state; - digitalWrite(proj_fwd_pin, LOW); - digitalWrite(proj_bwd_pin, LOW); + digitalWrite(proj_fwd_pin_1, LOW); + digitalWrite(proj_fwd_pin_2, LOW); + + digitalWrite(proj_bwd_pin_1, LOW); + digitalWrite(proj_bwd_pin_2, LOW); + digitalWrite(proj_bwd_pin_3, LOW); if (state) { - digitalWrite(proj_fwd_pin, HIGH); + digitalWrite(proj_fwd_pin_1, HIGH); + digitalWrite(proj_fwd_pin_2, HIGH); + Serial.println(cmd_proj_forward); log("proj_direction -> true"); } else { - digitalWrite(proj_bwd_pin, HIGH); + digitalWrite(proj_bwd_pin_1, HIGH); + digitalWrite(proj_bwd_pin_2, HIGH); + digitalWrite(proj_bwd_pin_3, HIGH); + Serial.println(cmd_proj_backward); log("proj_direction -> false"); } //delay(50); //delay after direction change to account for slippage of the belt } +void proj_second_direction (boolean state) { + proj_second_dir = state; + digitalWrite(proj_second_fwd_pin, LOW); + digitalWrite(proj_second_bwd_pin, LOW); + if (state) { + digitalWrite(proj_second_fwd_pin, HIGH); + Serial.println(cmd_proj_second_forward); + log("proj_second_direction -> true"); + } else { + digitalWrite(proj_second_bwd_pin, HIGH); + Serial.println(cmd_proj_second_backward); + log("proj_second_direction -> false"); + } +} + +void Pins_init () { + //Declare primary projector pins + pinMode(proj_fwd_pin_1, OUTPUT); + pinMode(proj_bwd_pin_1, OUTPUT); + pinMode(proj_fwd_pin_2, OUTPUT); + pinMode(proj_bwd_pin_2, OUTPUT); + pinMode(proj_bwd_pin_3, OUTPUT); + pinMode(proj_pin, OUTPUT); + + //declare secondary projector pins + pinMode(proj_second_fwd_pin, OUTPUT); + pinMode(proj_second_bwd_pin, OUTPUT); + pinMode(proj_second_pin, OUTPUT); + + //Set primary projector to forward + digitalWrite(proj_pin, LOW); + digitalWrite(proj_fwd_pin_1, HIGH); + digitalWrite(proj_fwd_pin_2, HIGH); + digitalWrite(proj_bwd_pin_1, LOW); + digitalWrite(proj_bwd_pin_2, LOW); + digitalWrite(proj_bwd_pin_3, LOW); + + //Set secondary projector to forward + digitalWrite(proj_second_fwd_pin, HIGH); + digitalWrite(proj_second_bwd_pin, LOW); + digitalWrite(proj_second_pin, LOW); + +} + void log (String msg) { if (debug_state) { Serial.println(msg); diff --git a/ino/mcopy_mono_firmware_projectors_secondary/mcopy_mono_firmware_projectors_secondary.ino b/ino/mcopy_mono_firmware_projectors_secondary/mcopy_mono_firmware_projectors_secondary.ino index 61fe6e1..c36e019 100644 --- a/ino/mcopy_mono_firmware_projectors_secondary/mcopy_mono_firmware_projectors_secondary.ino +++ b/ino/mcopy_mono_firmware_projectors_secondary/mcopy_mono_firmware_projectors_secondary.ino @@ -1,5 +1,5 @@ /** - * TEMPORARY + * TEMPORARY PROOF OF CONCEPT * * This is a specialized version of the mcopy firmware for * controlling the projectors of the optical printer