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
|
|
|
|
volatile int cameraFrame = 1200;
|
|
|
|
volatile char cmdChar = 'z';
|
|
|
|
volatile long now;
|
2023-04-11 04:38:06 +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
|
|
|
|
|
|
|
digitalWrite(CAMERA, HIGH);
|
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();
|
|
|
|
} else if (val == mc.STATE) {
|
|
|
|
state();
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-11 04:38:06 +00:00
|
|
|
digitalWrite(CAMERA, LOW);
|
2023-04-11 05:13:44 +00:00
|
|
|
digitalWrite(LED, HIGH);
|
2023-04-11 04:38:06 +00:00
|
|
|
delay(CAMERA_MOMENT);
|
|
|
|
digitalWrite(CAMERA, HIGH);
|
2023-04-11 05:13:44 +00:00
|
|
|
delay(cameraFrame - CAMERA_MOMENT);
|
|
|
|
digitalWrite(LED, LOW);
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 05:13:44 +00:00
|
|
|
void state () {
|
|
|
|
String stateString = String(mc.CAMERA_EXPOSURE);
|
|
|
|
stateString += String(cameraFrame);
|
|
|
|
stateString += String(mc.STATE);
|
|
|
|
mc.print(stateString);
|
2023-04-11 04:38:06 +00:00
|
|
|
}
|