Skip to content

Instantly share code, notes, and snippets.

@Grathio
Created September 12, 2011 03:51
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save Grathio/1210546 to your computer and use it in GitHub Desktop.
Save Grathio/1210546 to your computer and use it in GitHub Desktop.
Nikon Arduino Remote
// ----- C -------
/**
* arduino Nikon IR remote
* @license Creative commons: Attribution-Noncommercial-Share Alike 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
* @author Aurelien ANTOINE
* version 1
* date 20081217
*
*
* This version modified by Steve Hoefer September 12, 2011
* Changes:
* - Removed status light
* - Added pushbutton trigger
* Shared back to the community per the BY-NC-SA license.
* Retains the original BY-NC-SA License above.
**/
#define LEDPin 14
#define ButtonPin 15
#define FREQ 38400 // IR frequence
//shutter sequence (on,off,on,off ... in microsecond)
unsigned long sequence[] = {2000,27830,390,1580,410,3580,400,63200,2000,27830,390,1580,410,3580,400,0};
int seq_l;
//oscd is a delay in microsecond used at each oscillation.
int oscd;
void oscillate(int pin, unsigned long n, int shine){
int ir_status=0;
while(n>0){
n--;
delayMicroseconds(oscd);
ir_status = !ir_status;
digitalWrite(pin, ir_status && shine);
}
}
void snap(){
int i;
for(i=0;i<seq_l;i++){
oscillate(LEDPin, sequence[i], i%2==0);
}
digitalWrite(LEDPin, 0);
}
void setup() {
pinMode(ButtonPin, INPUT);
int min=1, max=100, i;
int last_oscd=0;
unsigned long before, intervalle;
oscd=max;
seq_l = sizeof(sequence)/sizeof(unsigned long);
pinMode(LEDPin, OUTPUT);
//this "while" will process the best "oscd"
while(last_oscd!=oscd){
last_oscd=oscd;
oscd=(min+max)>>1;
before=millis();
oscillate(LEDPin, FREQ, 1);
intervalle=millis()-before;
if(intervalle >= 1000) max=oscd;
else min=oscd;
}
//rewrite the sequence array, we replace all values in microsecond by the number of oscillation
for(i=0;i<seq_l;i++){
sequence[i] = (sequence[i] * FREQ) / (intervalle * 1000);
}
}
void loop() {
if (digitalRead(ButtonPin)==HIGH){
snap(); // take a photo when button pressed.
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment