Hey all,
First time poster, I made my first usable sketch (doesnt just blink at me :P) and im pretty proud so i thought id show it off. I'd also like to see if there are more efficient ways of doing anything in here, so please let me know. Basically its an IR remote/intervalometer for my Canon T2i that uses the Wii nunchuck for control. I plan on later adding a display but i just cannibalize parts 99% of the time so i have to find one first. Im going to try a night long HDR timelapse next weekend and ill try to post the results when i can. oh, and ive referenced the two other sketches i used at the begining if your wondering about libraries or other code.
/* NunShutter 1.0 2012 Kelly Jellison
Uses:
Wiichuck from 2008 Tod E. Kurt
and
Arduino sketch for simulating a Canon RC-1 IR remote control to do
timelapse photography with a compatible Canon DSLR
2010, Martin Koch
*/
#include <Wire.h>
#include "nunchuck_funcs.h"
#define statLED 13
#define irLED 12
int program = 0;
int timel = 0; //timelapse time between shots
int rate = 0; //rapid shot shoot rate
int start = 0;
int zbut = 0;
int cbut = 0;
int joyx = 0;
int joyy = 0;
int timep = 0;
int ratep = 0;
unsigned int pulseDuration = 10; //microseconds
//The required 15 microseconds pulseDuration didn't work since digitalWrite consumes some additional time
//thats adds to pulseDuration value. 10 to 12 microseconds worked for me.
unsigned int photo = 7330; //A 7330 microseconds delay between bursts shoots a photo.
unsigned int video = 5360; //A 5360 microseconds delay between bursts starts/stops video recording.
void setup()
{
pinMode(irLED, OUTPUT);
//Serial.begin(19200); //used for debug, uncomment when needed.
nunchuck_setpowerpins();
nunchuck_init();
}
void loop()
{
nunchuck_get_data();
zbut = nunchuck_zbutton();
cbut = nunchuck_cbutton();
joyx = nunchuck_joyx();
joyy = nunchuck_joyy();
if (program > 2)
{
program = 0;
}
if (zbut == 1)
{
program++;
}
if (joyy > 150)
{
rate++;
delay(10);
}
if (joyy < 100)
{
rate--;
delay(10);
}
if (joyx > 150)
{
timel++;
delay(10);
}
if (joyx < 100)
{
timel--;
delay (10);
}
timep = timel*1000;
ratep = rate*10;
/*
Serial.print("program "); Serial.println(program);
Serial.print("timel "); Serial.println(timel); //for debug
Serial.print("rate "); Serial.println(rate); //uncomment this section
Serial.print("timep "); Serial.println(timep);
Serial.print("ratep "); Serial.println(ratep);
Serial.print("zbut "); Serial.println(zbut);
Serial.print("cbut "); Serial.println(cbut);
Serial.println("--------");
delay(1000);
*/
digitalWrite(statLED, LOW);
if (cbut == 1)
{
digitalWrite(statLED, HIGH); //first thing it does is tell you the program selected is going to be initiated.
if (program == 0) //simple remote control program
{
shoot(photo);
digitalWrite(statLED, LOW);
}
if (program == 1) //rapid fire shooting based on "ratep" which increases by 10msecs
{
while (cbut > 0) //continues to shoot as long as c is held. (delay on release is more noticeable as rate increases.)
{
shoot(photo);
digitalWrite(statLED, LOW);
delay(ratep);
digitalWrite(statLED, HIGH);
nunchuck_get_data();
cbut = nunchuck_cbutton();
}
rate = 0; //both rate and timel would increment by one everytime the program stopped, this actually sets them to 1.
timel = 0;
}
if (program == 2) //timelapse program based on timep which increments by the second.
{
while (zbut < 1) //continues until z is pressed, but due to delay(timep) it has to be held until while reaches the end. (best to hold just after shooting)
{
shoot(photo);
digitalWrite(statLED, LOW);
delay(timep);
digitalWrite(statLED, HIGH);
nunchuck_get_data();
zbut = nunchuck_zbutton();
}
timel = 0;
rate = 0;
}
}
}
void shoot(unsigned int delayBetweenBursts) { //takes a shot, simple.
//send first 16 bursts
for(int i=0; i<16; i++) {
digitalWrite(irLED, HIGH);
delayMicroseconds(pulseDuration);
digitalWrite(irLED, LOW);
delayMicroseconds(pulseDuration);
}
delayMicroseconds(delayBetweenBursts);
//send second 16 bursts
for(int i=0; i<16; i++) {
digitalWrite(irLED, HIGH);
delayMicroseconds(pulseDuration);
digitalWrite(irLED, LOW);
delayMicroseconds(pulseDuration);
}
return;
}