something like this. Note: your code will have to call begin() to make the pinMode() call happen at the proper time
.h file
/*******************************************
Name.......: cameraIrControl Library
Description: A powerful Library to control easy various cameras via IR. Please check the project page and leave a comment.
Author.....: Sebastian Setz
Version....: 1.2
Date.......: 2010-12-16
Project....: http://sebastian.setz.name/arduino/my-libraries/multi-camera-ir-control
Contact....: http://Sebastian.Setz.name
License....: This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
Keywords...: arduino, library, camera, ir, control, canon, nikon, olympus, minolta, sony, pentax, interval, timelapse
********************************************/
#ifndef multiCameraIrControl_h
#define multiCameraIrControl_h
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
// base class for all cameras
class Camera
{
public:
Camera(uint8_t pin, uint8_t freq) : _pin(pin), _freq(freq) {};
virtual void shotNow() = 0; // pure virtual, must be defined in derived classes
virtual void shotDelayed(); // not all camera models have this
virtual void begin();
protected:
void wait(unsigned int);
void high(unsigned int);
uint8_t _pin;
uint8_t _freq;
};
class Nikon : public Camera
{
public:
Nikon(uint8_t pin) : Camera(pin, 40) {};
void shotNow();
//void shotDelayed();
};
class Pentax : public Camera
{
public:
Pentax(uint8_t pin) : Camera(pin, 38) {};
void shotNow();
//void shotDelayed();
};
class Olympus : public Camera
{
public:
Olympus(uint8_t pin) : Camera(pin, 40) {};
void shotNow();
//void shotDelayed();
};
class Minolta : public Camera
{
public:
Minolta(uint8_t pin) : Camera(pin, 38) {};
void shotNow();
void shotDelayed();
};
class Sony : public Camera
{
public:
Sony(uint8_t pin) : Camera(pin, 40) {};
void shotNow();
void shotDelayed();
};
class Canon : public Camera
{
public:
Canon(uint8_t pin) : Camera(pin, 33) {};
void shotNow();
void shotDelayed();
};
#endif
.cpp file
/*******************************************
Name.......: cameraIrControl Library
Description: A powerful Library to control easy various cameras via IR. Please check the project page and leave a comment.
Author.....: Sebastian Setz
Version....: 1.2
Date.......: 2010-12-16
Project....: http://sebastian.setz.name/arduino/my-libraries/multi-camera-ir-control
Contact....: http://Sebastian.Setz.name
License....: This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
Keywords...: arduino, library, camera, ir, control, canon, nikon, olympus, minolta, sony, pentax, interval, timelapse
********************************************/
#include "multiCameraIrControl.h"
void Camera::wait(unsigned int time) {
unsigned long start = micros();
while (micros() - start <= time) {
}
}
void Camera::high(unsigned int time) {
int pause = (1000 / _freq / 2) - 4;
unsigned long start = micros();
while (micros() - start <= time) {
digitalWrite(_pin, HIGH);
delayMicroseconds(pause);
digitalWrite(_pin, LOW);
delayMicroseconds(pause);
}
}
void Camera::begin()
{
pinMode(_pin, OUTPUT);
}
void Camera::shotDelayed()
{
// generic stub
}
void Nikon::shotNow()
{
high(2000);
wait(27830);
high(390);
wait(1580);
high(410);
wait(3580);
high(400);
}
void Pentax::shotNow()
{
high(13000);
wait(3000);
for (int i = 0; i < 7; i++) {
high(1000);
wait(1000);
};
}
void Olympus::shotNow()
{
const byte seq[] = { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 };
const byte count = sizeof(seq) / sizeof(seq[0]);
high(3800);
wait(4000);
high(550);
for (int i = 0; i < count; i++) {
if (seq[i]) {
wait(1500);
high(500);
}
else {
wait(500);
high(500);
}
}
}
void Minolta::shotNow()
{
const byte seq[] = { 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 };
const byte count = sizeof(seq) / sizeof(seq[0]);
high(3750);
wait(1890);
for (int i = 0; i < count; i++) {
if (seq[i]) {
high(456);
wait(1430);
}
else {
high(456);
wait(487);
}
}
}
void Minolta::shotDelayed()
{
const byte seq[] = { 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
const byte count = sizeof(seq) / sizeof(seq[0]);
high(3750);
wait(1890);
for (int i = 0; i < count; i++) {
if (seq[i]) {
high(456);
wait(1430);
}
else {
high(456);
wait(487);
}
}
}
void Sony::shotNow()
{
const byte seq[] = { 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1 };
const byte count = sizeof(seq) / sizeof(seq[0]);
high(2320);
for (int i = 0; i < count; i++) {
if (seq[i]) {
high(1175);
wait(650);
}
else {
high(575);
wait(650);
}
}
}
void Sony::shotDelayed()
{
const byte seq[] = { 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1 };
const byte count = sizeof(seq) / sizeof(seq[0]);
high(2320);
for (int i = 0; i < count; i++) {
if (seq[i]) {
high(1175);
wait(650);
}
else {
high(575);
wait(650);
}
}
}
void Canon::shotNow()
{
high(480);
wait(7330);
high(480);
}
void Canon::shotDelayed()
{
high(488);
wait(5360);
high(488);
}
Example
#include "multiCameraIrControl.h"
Nikon XXX(12);
Pentax pen(10);
Olympus oly(9);
Sony slr(11);
Canon A900(13);
Camera *camera;
void setup() {
A900.begin();
XXX.begin();
slr.begin();
camera = &A900;
camera->shotNow();
camera->shotDelayed();
}
void loop() {
}