Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 298 lines (231 sloc) 4.959 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
// Intervalometer and dolly motor controller
// Olli-Pekka Heinisuo 2011
// Licensed under MIT license, see LICENSE.txt
// This is experimental version, change to master branch if you want normal version

/*
This version does not include any motor functionality,
just plain, enchanced intervalometer! (for example star timelapses)
BULB-mode required, this version was made very long exposures in mind:
max interval 999 secs, max exposure time 999 secs
*/

// LCD library
#include <LiquidCrystal.h>
// These pins are not used by Adafruit motor shield if it's using only motor 1
LiquidCrystal lcd(10, 9, 5, 3, 2, 14);

// pin that will trigger the camera
#define CAMERA_PIN 13

// "exposing" or not, if false, sends pulse to the optocoupler
// which triggers the camera
bool exposing = false;

int c,s,t,r,e,b,m,p,n = 0;
int pause;
int counter = 0;
int interval;
int exposure;
int state;
int divi;
unsigned long time = 0;

void setup() {

pinMode(13, OUTPUT);
pinMode(A5, INPUT); // pins for the buttons
pinMode(A4, INPUT);
pinMode(A3, INPUT);
pinMode(CAMERA_PIN, OUTPUT); // to the optocoupler

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}

// These functions return a value when the corresponding button is pressed
// 1,8 kohm resistors were used between 6 buttons (7 resistors)
// More info: http://tronixstuff.wordpress.com/2011/01/11/tutorial-using-analog-input-for-multiple-buttons/
//
// Switches:
// 1 kohm resistors were used with 2 switches, total 6 resistors

// Reset button

int resetButton(int pin) {

c=analogRead(pin);

if (c<160 && c>100) {
r = 1; // reset button
}
return r;
}

/* coming later, sensor buttons for dolly
int shutDown(int pin) {

c=analogRead(pin);

if (c< && c>)
{
r = 1; // stop&reset to prevent any damage
}
return r;
}
*/

// interval time

int dig1Button(int pin) {

c=analogRead(pin);

if (c>160 && c<180)
{
delay(250); // if not set, value will increment as long as the button
// was pressed and we don't want that to happen (about 100-200 ms)
++e;
}
if (e < 999) {
return e;
}
else {
return e=0;
}
}

// interval time

int dig2Button(int pin) {

c=analogRead(pin);

if (c>180 && c<210)
{
delay(250);
--e;
}
if (e > 0) {
return e;
}
else {
return e=0;
}
}

// exposure time

int dig3Button(int pin) {

c=analogRead(pin);

if (c>330 && c<370)
{
delay(250);
++n;
}
if (n < 999) {
return n;
}
else {
return n=0;
}
}

// exposure time

int dig4Button(int pin) {

c=analogRead(pin);

if (c>240 && c<270)
{
delay(250);
--n;
}
if (n > 0) {
return n;
}
else {
return n=0;
}
}

// Start & stop

int startButton(int pin) {

c=analogRead(pin);

if (c>500 && c<600) {
delay(250);
s++;
}
if (s <= 1) {
return s;
}
else if (s > 1) {
return s=0;
}
}

/* select time range, default (0) is 0,0 - 9,9 seconds, (1) is 0-99 seconds

int timingSwitch(int pin) {

c=analogRead(pin);

if (c>450 && c < 550) {
return t=1;
}
else if (c < 450 && c>300) {
return t=0;
}
else if (c == 0) {
return t=2;
}
else {
return t=0;
}
}

// switch for choosing motor behavior: if on, motor moves without pauses, if off motor pauses when pic is taken

int motorSwitch(int pin) {

c=analogRead(pin);

if (c>450 && c < 550) {
return m=1;
}
else if (c < 450 && c>300) {
return m=0;
}
else if (c == 0) {
return m=2;
}
else {
return m=0;
}
}

*/

// This is where the magic happens

void loop() {

// If the reset button is pressed -> pause + every variable
// returns to their default values

if (r == 1 ) {

digitalWrite(CAMERA_PIN, LOW);
s = 0;
r = 0;
b = 0;
e = 0;
p = 0;
n = 0;
counter = 0;
lcd.clear();
}

// constantly updating the values enables the possibility
// to modify interval time on the fly

e = dig1Button(5); // interval
n = dig3Button(5); // exposure
e = dig2Button(5); // interval
n = dig4Button(5); // exposure
s = startButton(5); // start
r = resetButton(5); // reset (and stop)

// These are for LCD-display, type 16x2

// Interval


lcd.setCursor(0, 0);
lcd.print("Int:");
lcd.setCursor(4, 0);
lcd.print(e);

// Exposure time

lcd.setCursor(8, 0);
lcd.print("Exp:");
lcd.setCursor(12, 0);
lcd.print(n);

// Picture counter

lcd.setCursor(9, 1);
lcd.print("No:");
lcd.setCursor(12, 1);
lcd.print(counter);

if (s == 1) {

interval = e*1000; // full seconds, values from 0 to 999 seconds accepted
exposure = n*1000;

if (exposing == false) {

// enable optocoupler
digitalWrite(CAMERA_PIN, HIGH);
// set state 'high' for the pulse statement
state = HIGH;
time = millis();
exposing = true;
counter++; // counter, if LCD is in use
}

else if ( millis() - time >= exposure && state == HIGH && exposing == true)
{
digitalWrite(CAMERA_PIN, LOW);
state = LOW;
}

// sets the exposing flag to false when interval time has passed

else if ( millis() - time >= interval && exposing == true)
{
exposing = false;
}
}
}
Something went wrong with that request. Please try again.