Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 403 lines (315 sloc) 7.426 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
// Intervalometer and dolly motor controller
// Olli-Pekka Heinisuo 2011
// Licensed under MIT license, see LICENSE.txt
// This is experimental version, change to master if you want normal version

// AFMotor library
#include <AFMotor.h>
// 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

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

// motor speed, increments by 20
// no "zero" speed, because it can cause DC gearmotor to stall
// -> max current passes trough, if no fuse is used the motor can suffer damage
int speed[] = {75, 95, 115, 135, 155, 175, 195, 215, 235, 255};

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

AF_DCMotor motor(1, MOTOR12_64KHZ);

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;
}

*/

// digit 1 value control

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
e++; // was pressed and we don't want that to happen (about 100-200 ms)
}
if (e < 10) { // can't show numbers bigger than 9
return e;
}
else { // if value goes over 9, automatic reset will occur
return e=0;
}
}

// digit 2 value control

int dig2Button(int pin) {

c=analogRead(pin);

if (c>180 && c<210)
{
delay(250);
b++;
}
if (b < 10) {
return b;
}
else {
return b=0;
}
}

// digit 3 value control = motor speed

int dig3Button(int pin) {

c=analogRead(pin);

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

// digit 4 value control = pause time

int dig4Button(int pin) {

c=analogRead(pin);

if (c>240 && c<270)
{
delay(250);
p++;
}
if (p < 10) {
return p;
}
else {
return p=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);
t = 0;
s = 0;
r = 0;
b = 0;
e = 0;
p = 0;
// default speed is 9 (maximum)
n = 9;
m = 0;
counter = 0;
lcd.clear();
motor.run(RELEASE);
}

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

e = dig1Button(5); // first digit
b = dig2Button(5); // second digit
n = dig3Button(5); // third digit, motor speed
p = dig4Button(5); // fourth digit, pause time
s = startButton(5); // start
r = resetButton(5); // reset (and stop)
t = timingSwitch(4); // time range
m = motorSwitch(3); // pause / continuous mode

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

// Interval

if (t == 0) {
lcd.setCursor(0, 0);
lcd.print("Int:");
lcd.setCursor(4, 0);
lcd.print(e);
lcd.setCursor(5, 0);
lcd.print(",");
lcd.setCursor(6, 0);
lcd.print(b);
}
else if ( t == 1) {
lcd.setCursor(0, 0);
lcd.print("Int:");
lcd.setCursor(4, 0);
lcd.print(e);
lcd.setCursor(5, 0);
lcd.print(b);
lcd.setCursor(6, 0);
lcd.print("s");
}

// Time range

lcd.setCursor(8, 0);
lcd.print("R:");
lcd.setCursor(10, 0);
if (t == 0) {
lcd.print("n"); // normal
}
else if (t == 1) {
lcd.print("e"); // extended
}

// Motor speed

lcd.setCursor(12, 0);
lcd.print("Ms:");
lcd.setCursor(15, 0);
lcd.print(n);

// Pause time if pause mode on

lcd.setCursor(0, 1);
lcd.print("Pt:");
lcd.setCursor(3, 1);
lcd.print(p);

// Mode

lcd.setCursor(5, 1);
lcd.print("M:");
lcd.setCursor(7, 1);
if (m == 0) {
lcd.print("p"); // pause
}
else if (m == 1) {
lcd.print("c"); // continuous
}

// Picture counter

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

// Set the motor speed, 0 slowest and 9 fastest
// depends on motor type and supplied voltage

motor.setSpeed(speed[n]);

if (s == 1) {

if (m == 1) {
motor.run(FORWARD); // starts the dolly movement when in continuous movement mode
}

// These statements control the interval times

if (t == 0) {
interval = e*1000 + b*100; // turning the display values into milliseconds,
// max value being 9900 ms (9,9 seconds)
pause = p*100; // pause time, equivalent to exposure time
divi = 10; // pulse length divider
}
else if (t == 1) {
interval = e*10000 + b*1000; // full seconds, values from 0 to 99 seconds
pause = p*1000; // pause time, equivalent to exposure time
divi = 20; // pulse length divider
}

if (exposing == false) {

// shut motor down if option chosen

if (m == 0 && mot == 1) {
motor.run(RELEASE); // stops the dolly movement
mot = 0;
}

// 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
}

// The circuit needs to be closed for about 100 milliseconds
// so the camera has time to react
// pulse length (how long the circuit is closed),
// example: interval 2 sec, time range 0,1-9,9s, length 2000 ms / 10 = 200 ms

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

// pause time ends, starts the dolly movement again (if mode in use)

else if ( millis() - time >= pause && exposing == true && mot == 0)
{
motor.run(FORWARD);
mot = 1;
}

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

else if ( millis() - time >= interval && exposing == true)
{
exposing = false;
}

}

// force motor shutdown to prevent any damage

else {
motor.run(RELEASE);
}
}
Something went wrong with that request. Please try again.