2023-04-11 04:38:06 +00:00
|
|
|
/*
|
2023-04-11 05:13:44 +00:00
|
|
|
|
|
|
|
Control a camera with a single relay that
|
|
|
|
triggers a shutter release.
|
|
|
|
|
|
|
|
Hardware
|
|
|
|
|
|
|
|
Arduino Nano
|
|
|
|
Relay module
|
|
|
|
LED
|
|
|
|
480 Ohm resistor
|
|
|
|
|
2023-04-11 04:38:06 +00:00
|
|
|
Wiring
|
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
CAMERA
|
2023-04-11 04:38:06 +00:00
|
|
|
Wire directly to corresponding relay pins.
|
2023-04-11 05:13:44 +00:00
|
|
|
Arduino 2 5V GND
|
|
|
|
Relay 1 VCC GND
|
2023-04-11 04:38:06 +00:00
|
|
|
*/
|
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
#include "McopySerial.h"
|
2023-04-11 04:38:06 +00:00
|
|
|
|
|
|
|
//CAMERA CONSTANTS
|
|
|
|
const int CAMERA = 2;
|
2023-04-12 03:43:35 +00:00
|
|
|
const int BUTTON = 7;
|
2023-04-11 05:13:44 +00:00
|
|
|
const int LED = 8;
|
2023-04-11 04:38:06 +00:00
|
|
|
|
|
|
|
const int CAMERA_MOMENT = 240;
|
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
//VARIABLES
|
2024-04-20 00:09:44 +00:00
|
|
|
volatile int cameraFrame = 1000;
|
2023-04-11 05:13:44 +00:00
|
|
|
volatile char cmdChar = 'z';
|
|
|
|
volatile long now;
|
2023-04-11 04:38:06 +00:00
|
|
|
|
2023-07-05 18:46:43 +00:00
|
|
|
volatile String exposureString;
|
2024-04-20 00:09:44 +00:00
|
|
|
volatile long exposureTarget = 1000;
|
2023-07-05 18:46:43 +00:00
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
McopySerial mc;
|
2023-04-11 04:38:06 +00:00
|
|
|
|
|
|
|
void setup () {
|
|
|
|
pins();
|
2023-04-11 05:13:44 +00:00
|
|
|
digitalWrite(LED, HIGH);
|
|
|
|
mc.begin(mc.CAMERA_IDENTIFIER);
|
|
|
|
delay(42);
|
|
|
|
digitalWrite(LED, LOW);
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop () {
|
2023-04-11 05:13:44 +00:00
|
|
|
now = millis();
|
|
|
|
cmdChar = mc.loop();
|
|
|
|
cmd(cmdChar);
|
2023-04-12 03:43:35 +00:00
|
|
|
if (digitalRead(BUTTON) == LOW) {
|
|
|
|
camera();
|
|
|
|
}
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pins () {
|
|
|
|
pinMode(CAMERA, OUTPUT);
|
2023-04-11 05:13:44 +00:00
|
|
|
pinMode(LED, OUTPUT);
|
2023-04-12 03:43:35 +00:00
|
|
|
pinMode(BUTTON, INPUT_PULLUP);
|
2023-04-11 04:38:06 +00:00
|
|
|
|
2023-04-12 19:15:41 +00:00
|
|
|
digitalWrite(CAMERA, LOW);
|
2023-04-11 05:13:44 +00:00
|
|
|
digitalWrite(LED, LOW);
|
2023-04-11 04:38:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd (char val) {
|
2023-04-11 05:13:44 +00:00
|
|
|
if (val == mc.CAMERA_FORWARD) {
|
|
|
|
camera_direction(true);
|
|
|
|
} else if (val == mc.CAMERA_BACKWARD) {
|
|
|
|
camera_direction(false);
|
|
|
|
} else if (val == mc.CAMERA) {
|
|
|
|
camera();
|
2023-07-05 18:46:43 +00:00
|
|
|
} else if (val == mc.CAMERA_EXPOSURE) {
|
|
|
|
exposure();
|
2023-04-11 05:13:44 +00:00
|
|
|
} else if (val == mc.STATE) {
|
|
|
|
state();
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 18:46:43 +00:00
|
|
|
void exposure () {
|
|
|
|
exposureString = mc.getString();
|
|
|
|
parseExposureString();
|
|
|
|
cameraFrame = exposureTarget;
|
|
|
|
mc.confirm(mc.CAMERA_EXPOSURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void parseExposureString () {
|
|
|
|
exposureTarget = exposureString.toInt();
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
//null route direction
|
|
|
|
void camera_direction (boolean state) {
|
|
|
|
if (state) {
|
|
|
|
mc.confirm(mc.CAMERA_FORWARD);
|
|
|
|
mc.log("camera_direction(true)");
|
2023-04-11 04:38:06 +00:00
|
|
|
} else {
|
2023-04-11 05:13:44 +00:00
|
|
|
mc.confirm(mc.CAMERA_BACKWARD);
|
|
|
|
mc.log("camera_direction(false)");
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
void camera () {
|
2023-04-12 19:15:41 +00:00
|
|
|
digitalWrite(CAMERA, HIGH);
|
2023-04-11 05:13:44 +00:00
|
|
|
digitalWrite(LED, HIGH);
|
2023-04-11 04:38:06 +00:00
|
|
|
delay(CAMERA_MOMENT);
|
2023-04-12 19:15:41 +00:00
|
|
|
digitalWrite(CAMERA, LOW);
|
2023-04-11 05:13:44 +00:00
|
|
|
delay(cameraFrame - CAMERA_MOMENT);
|
|
|
|
digitalWrite(LED, LOW);
|
2023-04-12 19:25:41 +00:00
|
|
|
mc.confirm(mc.CAMERA);
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
void state () {
|
2023-06-17 17:08:00 +00:00
|
|
|
String stateString = String(mc.STATE);
|
|
|
|
stateString += String(mc.CAMERA_EXPOSURE);
|
2023-04-11 05:13:44 +00:00
|
|
|
stateString += String(cameraFrame);
|
|
|
|
stateString += String(mc.STATE);
|
2023-06-17 17:08:00 +00:00
|
|
|
mc.sendString(stateString);
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|