mcopy/ino/mcopy_cam_relay/mcopy_cam_relay.ino

97 lines
1.6 KiB
Arduino
Raw Normal View History

2023-04-11 04:38:06 +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
CAMERA
2023-04-11 04:38:06 +00:00
Wire directly to corresponding relay pins.
Arduino 2 5V GND
Relay 1 VCC GND
2023-04-11 04:38:06 +00:00
*/
#include "McopySerial.h"
2023-04-11 04:38:06 +00:00
//CAMERA CONSTANTS
const int CAMERA = 2;
const int LED = 8;
2023-04-11 04:38:06 +00:00
const int CAMERA_MOMENT = 240;
//VARIABLES
volatile int cameraFrame = 1200;
volatile char cmdChar = 'z';
volatile long now;
2023-04-11 04:38:06 +00:00
McopySerial mc;
2023-04-11 04:38:06 +00:00
void setup () {
pins();
digitalWrite(LED, HIGH);
mc.begin(mc.CAMERA_IDENTIFIER);
delay(42);
digitalWrite(LED, LOW);
2023-04-11 04:38:06 +00:00
}
void loop () {
now = millis();
cmdChar = mc.loop();
cmd(cmdChar);
2023-04-11 04:38:06 +00:00
}
void pins () {
pinMode(CAMERA, OUTPUT);
pinMode(LED, OUTPUT);
2023-04-11 04:38:06 +00:00
digitalWrite(CAMERA, HIGH);
digitalWrite(LED, LOW);
2023-04-11 04:38:06 +00:00
}
void cmd (char val) {
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
}
}
//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 {
mc.confirm(mc.CAMERA_BACKWARD);
mc.log("camera_direction(false)");
2023-04-11 04:38:06 +00:00
}
}
void camera () {
2023-04-11 04:38:06 +00:00
digitalWrite(CAMERA, LOW);
digitalWrite(LED, HIGH);
2023-04-11 04:38:06 +00:00
delay(CAMERA_MOMENT);
digitalWrite(CAMERA, HIGH);
delay(cameraFrame - CAMERA_MOMENT);
digitalWrite(LED, LOW);
2023-04-11 04:38:06 +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
}