2023-03-10 02:54:54 +00:00
|
|
|
/*
|
|
|
|
* Sketch containing firmware for the JKMM100
|
|
|
|
* A collaboration between MONO NO AWARE and mcopy.
|
|
|
|
* Compatible with JK105 hardware.
|
|
|
|
*
|
|
|
|
* Uses an Arduino Uno compatible board and a
|
|
|
|
* custom PCB.
|
|
|
|
* Rrelay module for proj :
|
|
|
|
|
|
|
|
Wiring
|
|
|
|
|
|
|
|
PROJECTOR + PROJECTOR_DIR
|
|
|
|
|
|
|
|
Wire to corresponding pins
|
2023-03-18 21:36:24 +00:00
|
|
|
Arduino 3 4 5V GND
|
2023-03-10 02:54:54 +00:00
|
|
|
Relay 1 2 VCC GND
|
|
|
|
|
|
|
|
For controling JK Projectors 106 models
|
|
|
|
Solid state relays connect to:
|
|
|
|
2uf run capacitory
|
|
|
|
400 Ohm Resistor (50W)
|
|
|
|
|
|
|
|
|
|
|
|
PINS FOR PROJ WIRE
|
|
|
|
|
|
|
|
#
|
|
|
|
1 -
|
|
|
|
2 -
|
|
|
|
3 -
|
|
|
|
4 -
|
|
|
|
|
|
|
|
Relay 1 corresponds to FWD
|
|
|
|
Relay 2 corresponse to BWD
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "McopySerial.h"
|
|
|
|
|
|
|
|
volatile unsigned long now;
|
|
|
|
|
|
|
|
//PROJECTOR CONSTANTS
|
2023-04-12 02:39:44 +00:00
|
|
|
const int PROJECTOR_MICROSWITCH = 11;
|
|
|
|
const int LED_FWD = 12;
|
|
|
|
const int LED_BWD = 13;
|
2023-03-10 02:54:54 +00:00
|
|
|
|
2023-03-18 21:36:24 +00:00
|
|
|
const int PROJECTOR_FWD = 3;
|
|
|
|
const int PROJECTOR_BWD = 4;
|
2023-03-10 02:54:54 +00:00
|
|
|
|
|
|
|
const int PROJECTOR_MOMENT = 240;
|
|
|
|
const int PROJECTOR_FRAME = 600;
|
|
|
|
const int PROJECTOR_MICROSWITCH_CLOSED = 0;
|
|
|
|
const int PROJECTOR_MICROSWITCH_OPENED = 1;
|
|
|
|
const int PROJECTOR_HALF_TIME = 450;
|
|
|
|
|
|
|
|
//PROJECTOR VARIABLES
|
|
|
|
boolean proj_dir = true;
|
|
|
|
boolean proj_running = false;
|
|
|
|
boolean proj_primed = false;
|
|
|
|
volatile int proj_micro_state = 0;
|
|
|
|
volatile long proj_time = 0;
|
2023-03-18 21:25:58 +00:00
|
|
|
volatile long proj_avg = -1;
|
2023-03-10 02:54:54 +00:00
|
|
|
|
|
|
|
volatile char cmdChar = 'z';
|
|
|
|
|
2023-03-22 00:35:00 +00:00
|
|
|
McopySerial mc;
|
2023-03-10 02:54:54 +00:00
|
|
|
|
|
|
|
void setup () {
|
|
|
|
pins();
|
2023-04-11 04:24:39 +00:00
|
|
|
digitalWrite(LED_FWD, HIGH);
|
|
|
|
digitalWrite(LED_BWD, HIGH);
|
2023-03-22 00:35:00 +00:00
|
|
|
mc.begin(mc.PROJECTOR_IDENTIFIER);
|
2023-04-11 04:24:39 +00:00
|
|
|
delay(42);
|
|
|
|
digitalWrite(LED_FWD, LOW);
|
|
|
|
digitalWrite(LED_BWD, LOW);
|
2023-03-10 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop () {
|
|
|
|
now = millis();
|
|
|
|
if (proj_running) {
|
|
|
|
proj_microswitch();
|
|
|
|
} else {
|
2023-03-22 00:35:00 +00:00
|
|
|
cmdChar = mc.loop();
|
2023-03-10 02:54:54 +00:00
|
|
|
cmd(cmdChar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pins () {
|
|
|
|
pinMode(PROJECTOR_MICROSWITCH, INPUT_PULLUP);
|
|
|
|
pinMode(PROJECTOR_FWD, OUTPUT);
|
|
|
|
pinMode(PROJECTOR_BWD, OUTPUT);
|
2023-04-11 03:28:02 +00:00
|
|
|
pinMode(LED_FWD, OUTPUT);
|
|
|
|
pinMode(LED_BWD, OUTPUT);
|
2023-03-10 02:54:54 +00:00
|
|
|
|
2023-03-20 23:45:32 +00:00
|
|
|
digitalWrite(PROJECTOR_FWD, HIGH);
|
|
|
|
digitalWrite(PROJECTOR_BWD, HIGH);
|
2023-04-11 04:24:39 +00:00
|
|
|
|
|
|
|
digitalWrite(LED_FWD, LOW);
|
|
|
|
digitalWrite(LED_BWD, LOW);
|
2023-03-10 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmd (char val) {
|
2023-03-22 00:35:00 +00:00
|
|
|
if (val == mc.PROJECTOR_FORWARD) {
|
2023-03-18 21:36:24 +00:00
|
|
|
proj_direction(true);
|
2023-03-22 00:35:00 +00:00
|
|
|
} else if (val == mc.PROJECTOR_BACKWARD) {
|
2023-03-10 02:54:54 +00:00
|
|
|
proj_direction(false);
|
2023-03-22 00:35:00 +00:00
|
|
|
} else if (val == mc.PROJECTOR) {
|
2023-03-10 02:54:54 +00:00
|
|
|
proj_start();
|
2023-03-22 00:35:00 +00:00
|
|
|
} else if (val == mc.STATE) {
|
2023-03-18 21:25:58 +00:00
|
|
|
state();
|
2023-03-10 02:54:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void proj_start () {
|
|
|
|
proj_time = millis();
|
|
|
|
|
|
|
|
if (proj_dir) {
|
2023-03-20 23:45:32 +00:00
|
|
|
digitalWrite(PROJECTOR_FWD, LOW);
|
2023-04-11 03:28:02 +00:00
|
|
|
digitalWrite(LED_FWD, HIGH);
|
2023-03-10 02:54:54 +00:00
|
|
|
} else {
|
2023-03-20 23:45:32 +00:00
|
|
|
digitalWrite(PROJECTOR_BWD, LOW);
|
2023-04-11 03:28:02 +00:00
|
|
|
digitalWrite(LED_FWD, HIGH);
|
2023-03-10 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proj_running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void proj_stop () {
|
|
|
|
//stop both directions
|
|
|
|
delay(10);
|
2023-03-20 23:45:32 +00:00
|
|
|
digitalWrite(PROJECTOR_FWD, HIGH);
|
|
|
|
digitalWrite(PROJECTOR_BWD, HIGH);
|
2023-04-11 03:28:02 +00:00
|
|
|
digitalWrite(LED_FWD, LOW);
|
|
|
|
digitalWrite(LED_BWD, LOW);
|
2023-03-10 02:54:54 +00:00
|
|
|
|
2023-03-22 00:35:00 +00:00
|
|
|
mc.confirm(mc.PROJECTOR);
|
2023-03-10 02:54:54 +00:00
|
|
|
mc.log("projector()");
|
|
|
|
proj_running = false;
|
|
|
|
|
2023-03-18 21:25:58 +00:00
|
|
|
update_timing(millis() - proj_time);
|
2023-03-10 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void proj_direction (boolean state) {
|
|
|
|
proj_dir = state;
|
|
|
|
if (state) {
|
2023-03-22 00:35:00 +00:00
|
|
|
mc.confirm(mc.PROJECTOR_FORWARD);
|
2023-03-10 02:54:54 +00:00
|
|
|
mc.log("proj_direction -> true");
|
|
|
|
} else {
|
2023-03-22 00:35:00 +00:00
|
|
|
mc.confirm(mc.PROJECTOR_BACKWARD);
|
2023-03-10 02:54:54 +00:00
|
|
|
mc.log("proj_direction -> false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOW=0=CLOSED
|
|
|
|
//HIGH=1=OPEN
|
|
|
|
void proj_microswitch () {
|
|
|
|
int val = digitalRead(PROJECTOR_MICROSWITCH);
|
|
|
|
if (!proj_primed // if not primed
|
|
|
|
&& val != proj_micro_state // AND if state changes
|
|
|
|
&& val == PROJECTOR_MICROSWITCH_OPENED // AND state changes to open
|
|
|
|
&& now - proj_time > PROJECTOR_HALF_TIME) {
|
|
|
|
//prime
|
|
|
|
mc.log("proj_primed => true");
|
|
|
|
proj_micro_state = val;
|
|
|
|
proj_primed = true;
|
|
|
|
} else if (proj_primed //if primed
|
|
|
|
&& val != proj_micro_state //AND if state changes
|
|
|
|
&& val == PROJECTOR_MICROSWITCH_CLOSED //AND state changes to open
|
|
|
|
&& now - proj_time > PROJECTOR_HALF_TIME) { //AND total elapsed time is greater than half frame time
|
|
|
|
//stop
|
|
|
|
proj_primed = false;
|
|
|
|
proj_micro_state = val; //unneeded?
|
|
|
|
proj_stop();
|
|
|
|
} else {
|
|
|
|
//delay(2); //some smothing value
|
|
|
|
}
|
|
|
|
}
|
2023-03-18 21:25:58 +00:00
|
|
|
|
|
|
|
void update_timing (int timing) {
|
|
|
|
if (proj_avg == -1) {
|
|
|
|
proj_avg = timing;
|
|
|
|
} else {
|
|
|
|
proj_avg = (int) round((proj_avg + timing) / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void state () {
|
2023-03-22 00:35:00 +00:00
|
|
|
String stateString = String(mc.CAMERA_EXPOSURE);
|
2023-03-18 21:25:58 +00:00
|
|
|
stateString += String(proj_avg);
|
2023-03-22 00:35:00 +00:00
|
|
|
stateString += String(mc.STATE);
|
2023-03-18 21:25:58 +00:00
|
|
|
mc.print(stateString);
|
|
|
|
}
|