Shutter timing arduino code

This is a follow-up to last weekend’s video about using an arduino to time camera shutters.

Here’s the source, in its diminutive glory:

//Connect the photo diode to analog input 0
//Connect the timer output to digital pin 3 (interrupt 1)
#define PDINPUT 0
#define THRESH 512

volatile unsigned int pulseCt;

void setup(void)

void loop(void)
  int last;
  int cur;
    cur = inputBlock(PDINPUT);
    if( cur >= THRESH && last < THRESH )
      pulseCt = 0;
      attachInterrupt(1, clock, RISING);
      while( inputBlock(PDINPUT) > THRESH );

    last = cur;

void clock(void)

//Rudimentary approach to flattening sampling noise -- adapt as required.
inline int inputBlock(const int pin)
  int a;
  a = analogRead(pin);
  a += analogRead(pin);
  return a / 2; 
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s