Hi all,
I want to use a camera flash with a camera that doesnt have a flash sync output signal.
My setup uses a remote control that triggers the camera and also sends a signal to an Arduino Nano as the flash would fire too early if I were to hook it up directly.
I want to use the Arduino to create an adjustable delay and then trigger the flash with it.
I am not completely new to Arduinos but I would still consider myself as a beginner so I am not familiar with many things that are or are not possible.
I was able to create a code with a hard coded delay, that worked out ok for my setup but when using a different flash I needed a slightly different delay. Always reprogramming it is not an option here so I wanted to make the delay adjustable. The adjustable range needs to be ~4ms in 100 μs steps with a base delay of 18ms. The flash needs to be fired within a few hundrered us if adjusted correctly.
With this adjustable code I also added an I²C display to see the current value.
This code did work but the actual delay was all over the place and not really what I set with a potentiometer. I wasn't able to sync up the flash with the camera that way.
I thought that maybe an interrupt based code would work here so I changed it accordingly just to find out that delays dont work within an interrupt.
So I know that the code below does not work.
Can anyone give me some advice on how I can code this to whenever I have a falling edge on my camera trigger pin (physically soldered to Pin D8 on my current board) ?
const int ExposureStartInterrupt = 0;
const int FlashPin = 3;
const int DelayPotentiometer = A7;
int buttonState = 0;
int outputValue = 0;
volatile int usDelay = 0;
volatile int BaseDelay = 18;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
pinMode(FlashPin, OUTPUT);
attachInterrupt(ExposureStartInterrupt, FireFlash, FALLING);
attachInterrupt(ExposureStartInterrupt, StopFlash, RISING);
pinMode(DelayPotentiometer, INPUT);
}
void loop() {
usDelay = analogRead(DelayPotentiometer);
usDelay = map(usDelay, 0, 1023, 0, 4000);
usDelay = usDelay / 100;
usDelay = usDelay * 100; //just to get rid of low μs values
outputValue = usDelay + (BaseDelay * 1000);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
for(;;);
}
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0, 28);
display.print(outputValue);
display.print("us");
display.display();
}
void FireFlash() {
delay(BaseDelay);
delayMicroseconds(usDelay);
digitalWrite(FlashPin, HIGH);
}
void StopFlash() {
digitalWrite(FlashPin, LOW);
}