-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino_sketch
504 lines (466 loc) · 14.6 KB
/
arduino_sketch
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/***********************************************************************
Credits goes to George Christidis, he mades the original ir emmiter function that i'm using in this project.
https://www.christidis.info/index.php/personal-projects/arduino-nikon-infrared-command-code
Components
1 x 330ohms resisotor
5 x 10komhs resistors
1 x IR emmiter (from an old tv remote controler or something like that)
6 x push buttons
1 x MAX7219 8 Bits Digital Segment LED Display
1 x Arduino uno
Wires, a fancy box, a power source, imagination... Lot of glue ^^
Building
IR EMMITER -> Negative to ground, positive in series with a 330ohm resistor to pin 7
Reset Button -> Negative to ground, positive to reset pin
Button Plus -> Negative to ground, positive pin to 2 and bridge it with a 10kohm resistor to 5v
Button Minus -> Negative to ground, positive pin to 3 and bridge it with a 10kohm resistor to 5v
Button Enter -> Negative to ground, positive pin to 4 and bridge it with a 10kohm resistor to 5v
Button Back -> Negative to ground, positive pin to 5 and bridge it with a 10kohm resistor to 5v
Button GO -> Negative to ground, positive pin to 6 and bridge it with a 10kohm resistor to 5v
LCD SCREEN -> DIN pin 12, CLK pin 10, LOAD pin 9, ground to ground, vcc to 5v
***********************************************************************/
////////////////////////////////////////////////////////////////////////
//////////////// DEFINE YOUR CAMERA MODEL AS DEFAULT ///////////////////
////////////////////////////////////////////////////////////////////////
/*
NIKON ---> 1
CANON ---> 2
SONY ---> 3
PENTAX ---> 4
PANASONIC ---> 5
OLYMPUS ---> 6
LEICA ---> 7
SIGMA ---> 8
*/
// Default variables
int model = 1; //NIKON
int program = 1;
// Variables
int shutter, interval, intervalLapse, numPictures, storeNum;
bool weAreInModeSelection, shutter_interval, shutter_interval_start, time_Lapse_start, lapse_interval;
// Switches pin connection and LED display to Arduino UNO
#include "LedControl.h" // Library used for communcation with 7 segment
LedControl lc = LedControl(12, 10, 9, 1); // (DIN, CLK, LOAD, number of Max7219 chips)
#define plus 2
#define minus 3
#define enter 4
#define back 5
#define go 6
#define IR_EMITTER 7
void setup() {
pinMode( IR_EMITTER, OUTPUT);
pinMode( plus, INPUT_PULLUP);
pinMode( minus, INPUT_PULLUP);
pinMode( back, INPUT_PULLUP);
pinMode( enter, INPUT_PULLUP);
pinMode( go, INPUT_PULLUP);
lc.shutdown(0, false); // Wake up MAX7219
lc.setIntensity(0, 1); // Set brightness to low
lc.clearDisplay(0); // Clear all displays connected to MAX7219 chip #
// Put zeros on both displays at startup
lc.setChar( 0, 0, ' ', false); // (Max7219 chip #, Digit, value, DP on or off)
lc.setChar( 0, 1, ' ', false);
lc.setChar( 0, 2, ' ', false);
lc.setChar( 0, 3, ' ', false);
lc.setChar( 0, 4, ' ', false);
lc.setChar( 0, 5, ' ', false);
lc.setChar( 0, 6, ' ', false);
lc.setChar( 0, 7, ' ', false);
}
// START AND PROMPT FOR PROGRAM SELECTION
void loop() {
// PROGRAM 1 --> Single shot mode
// PROGRAM 2 --> Shutter time / interval time mode
// PROGRAM 3 --> Time Lapse mode
// PROGRAM 4 --> Camera Model
if (!weAreInModeSelection) {//We are at mode screen selection
setProgram();
} else { //We are in one of the desired programs
switch (program) {
case 1: // Single Shot
lc.setChar( 0, 7, ' ', true); lc.setChar( 0, 6, ' ', true); lc.setChar( 0, 5, ' ', true); lc.setChar( 0, 4, ' ', true);
lc.setChar( 0, 3, ' ', true); lc.setChar( 0, 2, ' ', true); lc.setChar( 0, 1, ' ', true); lc.setChar( 0, 0, ' ', true);
singleShot();
returnMainScreen();
break;
case 2: // Shuter_time/Interval
shutterTime();
returnMainScreen();
break;
case 3: // Time Lapse
timeLapse();
returnMainScreen();
break;
case 4: // Camera Model
changeModel();
returnMainScreen();
break;
}
}
}
///////////////
// Functions //
///////////////
int gD(int val, int pos) { // Input number and split it into single digits for the led display.
char digits[6];
digits[0] = (val / 1) % 10;
digits[1] = (val / 10) % 10;
digits[2] = (val / 100) % 10;
digits[3] = (val / 1000) % 10;
digits[4] = (val / 10000) % 10;
digits[5] = (val / 100000) % 10;
return digits[pos];
}
void setProgram() { //switch between single shot, timed shutter and time lapse modes.
// Set the display to show the default configuration.
lc.setChar( 0, 7, 'P', false);
lc.setChar( 0, 6, '-', false);
lc.setChar( 0, 1, gD(model, 1), false);
lc.setChar( 0, 0, gD(model, 0), false);
lc.setChar( 0, 2, 'C', false);
lc.setChar( 0, 5, gD(program, 1), false);
lc.setChar( 0, 4, gD(program, 0), false);
if (!digitalRead(enter)) { // SELECT THE DESIRED PROGRAM AND GO ON
lc.clearDisplay(0);
weAreInModeSelection = true;
while (!digitalRead(enter)) { // Wait until switch is released to continue
}
delay(5); // Small delay to debounce the switch
}
if (!digitalRead(plus)) { // Promgram +
program++;
while (!digitalRead(plus)) { // Wait until switch is released to continue
}
delay(5); // Small delay to debounce the switch
}
if (!digitalRead(minus)) {
program--;
while (!digitalRead(minus)) {
}
delay(5);
}
// Set limit for mode
if (program > 4) {
program = 1;
}
if (program < 1) {
program = 4;
}
return program;
}
void returnMainScreen() { // go back to main screen from another mode
if (!digitalRead(back)) { // Go back to main page
lc.clearDisplay(0);
weAreInModeSelection = false;
while (!digitalRead(back)) {
}
delay(5);
}
}
void singleShot() { // Used for taking pictures in manual mode with a chronometer.
if (!digitalRead(go)) { // Take a single shot and start de clock.
takePhoto(model);
while (!digitalRead(go)) {
}
delay(5);
lc.clearDisplay(0);
for (int k = 0; k <= 99999; k++) { // Chronometer 4 digits plus one decimal
lc.setDigit(0, 4, gD(k, 4), false);
lc.setDigit(0, 3, gD(k, 3), false);
lc.setDigit(0, 2, gD(k, 2), false);
lc.setDigit(0, 1, gD(k, 1), true);
lc.setDigit(0, 0, gD(k, 0), false);
if (!digitalRead(go)) { // Take another shot and start the time again
takePhoto(model);
k = 0;
while (!digitalRead(go)) {
}
delay(5);
}
if (!digitalRead(back)) { // Stop and go to main screen
returnMainScreen();
break;
while (!digitalRead(back)) {
}
delay(5);
}
delay(99); // realtime clock!!! lol, just kidding, this is a fucking crap....
}
}
}
void shutterTime() { // Shutter time fixed to a number and shot every X interval time.
// Default values at the start
lc.setDigit(0, 7, gD(shutter, 2), false); lc.setDigit(0, 6, gD(shutter, 1), false); lc.setDigit(0, 5, gD(shutter, 0), false);
lc.setDigit(0, 2, gD(interval, 2), false); lc.setDigit(0, 1, gD(interval, 1), false); lc.setDigit(0, 0, gD(interval, 0), false);
if (shutter_interval_start && shutter > 0 && interval > 0) { // Start only if the interval and shutter time are not 0.
while (shutter_interval_start) {
takePhoto(model);
for (int i = shutter; i > 0; i--) {
lc.setDigit(0, 7, gD(i, 2), false);
lc.setDigit(0, 6, gD(i, 1), false);
lc.setDigit(0, 5, gD(i, 0), false);
delay(999);
}
takePhoto(model);
lc.setDigit(0, 7, gD(shutter, 2), false); lc.setDigit(0, 6, gD(shutter, 1), false); lc.setDigit(0, 5, gD(shutter, 0), false);
if (!digitalRead(go)) {
shutter_interval_start = false;
while (!digitalRead(go)) {
}
delay(5);
}
delay(interval * 1000);
}
}
if (!digitalRead(go)) {
shutter_interval_start = true;
while (!digitalRead(go)) {
}
delay(5);
}
if (!digitalRead(enter)) { // SELECT BETWEEN SHUTTER AND INTERVAL COUNTER
if (!shutter_interval) {
shutter_interval = true;
} else {
shutter_interval = false;
}
while (!digitalRead(enter)) {
}
delay(5);
}
if (!shutter_interval) {
if (!digitalRead(plus)) {
shutter++;
lc.setDigit(0, 7, gD(shutter, 2), false);
lc.setDigit(0, 6, gD(shutter, 1), false);
lc.setDigit(0, 5, gD(shutter, 0), false);
while (!digitalRead(plus)) {
}
delay(5);
}
if (!digitalRead(minus)) {
shutter--;
if (shutter < 0) {
shutter = 0;
}
lc.setDigit(0, 7, gD(shutter, 2), false);
lc.setDigit(0, 6, gD(shutter, 1), false);
lc.setDigit(0, 5, gD(shutter, 0), false);
while (!digitalRead(minus)) {
}
delay(5);
}
} else {
if (!digitalRead(plus)) {
interval++;
lc.setDigit(0, 2, gD(interval, 2), false);
lc.setDigit(0, 1, gD(interval, 1), false);
lc.setDigit(0, 0, gD(interval, 0), false);
while (!digitalRead(plus)) {
}
delay(5);
}
if (!digitalRead(minus)) {
interval--;
if (interval < 0) {
interval = 0;
}
lc.setDigit(0, 2, gD(interval, 2), false);
lc.setDigit(0, 1, gD(interval, 1), false);
lc.setDigit(0, 0, gD(interval, 0), false);
while (!digitalRead(minus)) {
}
delay(5);
}
}
}
void timeLapse() {
lc.setDigit(0, 7, gD(numPictures, 3), false); lc.setDigit(0, 6, gD(numPictures, 2), false); lc.setDigit(0, 5, gD(numPictures, 1), false); lc.setDigit(0, 4, gD(numPictures, 0), false);
lc.setDigit(0, 3, gD(intervalLapse, 3), false); lc.setDigit(0, 2, gD(intervalLapse, 2), false); lc.setDigit(0, 1, gD(intervalLapse, 1), true); lc.setDigit(0, 0, gD(intervalLapse, 0), false);
if (time_Lapse_start && numPictures > 0 && intervalLapse > 0) { // We are takking pictures right now.
while (numPictures > 0) {
numPictures--;
lc.setDigit(0, 7, gD(numPictures, 3), false);
lc.setDigit(0, 6, gD(numPictures, 2), false);
lc.setDigit(0, 5, gD(numPictures, 1), false);
lc.setDigit(0, 4, gD(numPictures, 0), false);
takePhoto(model);
delay(intervalLapse * 100);
if (!digitalRead(go)) {
time_Lapse_start = false;
storeNum = numPictures;
numPictures = 0;
while (!digitalRead(go)) {
}
delay(5);
}
}
time_Lapse_start = false;
numPictures = storeNum;
}
if (!digitalRead(go)) {
time_Lapse_start = true;
while (!digitalRead(go)) {
}
delay(5);
}
if (!digitalRead(enter)) {
if (!lapse_interval) {
lapse_interval = true;
} else {
lapse_interval = false;
}
while (!digitalRead(enter)) {
}
delay(5);
}
if (!lapse_interval) {
if (!digitalRead(plus)) {
numPictures = numPictures + 10;
lc.setDigit(0, 7, gD(numPictures, 3), false);
lc.setDigit(0, 6, gD(numPictures, 2), false);
lc.setDigit(0, 5, gD(numPictures, 1), false);
lc.setDigit(0, 4, gD(numPictures, 0), false);
while (!digitalRead(plus)) {
}
delay(5);
}
if (!digitalRead(minus)) {
numPictures = numPictures - 10;
if (numPictures < 0) {
numPictures = 0;
}
lc.setDigit(0, 7, gD(numPictures, 3), false);
lc.setDigit(0, 6, gD(numPictures, 2), false);
lc.setDigit(0, 5, gD(numPictures, 1), false);
lc.setDigit(0, 4, gD(numPictures, 0), false);
while (!digitalRead(minus)) {
}
delay(5);
}
} else {
if (!digitalRead(plus)) {
intervalLapse = intervalLapse + 5;
lc.setDigit(0, 3, gD(intervalLapse, 3), false);
lc.setDigit(0, 2, gD(intervalLapse, 2), false);
lc.setDigit(0, 1, gD(intervalLapse, 1), true);
lc.setDigit(0, 0, gD(intervalLapse, 0), false);
while (!digitalRead(plus)) {
}
delay(5);
}
if (!digitalRead(minus)) {
intervalLapse = intervalLapse - 5;
if (intervalLapse < 0) {
intervalLapse = 0;
}
lc.setDigit(0, 3, gD(intervalLapse, 3), false);
lc.setDigit(0, 2, gD(intervalLapse, 2), false);
lc.setDigit(0, 1, gD(intervalLapse, 1), true);
lc.setDigit(0, 0, gD(intervalLapse, 0), false);
while (!digitalRead(minus)) {
}
delay(5);
}
}
}
void changeModel() {
lc.setChar( 0, 7, 'C', false);
lc.setChar( 0, 6, '-', false);
lc.setChar( 0, 5, gD(model, 1), false);
lc.setChar( 0, 4, gD(model, 0), false);
if (!digitalRead(enter)) {
lc.clearDisplay(0);
weAreInModeSelection = true;
while (!digitalRead(enter)) {
}
delay(5);
}
if (!digitalRead(plus)) {
model++;
while (!digitalRead(plus)) {
}
delay(5);
}
if (!digitalRead(minus)) {
model--;
while (!digitalRead(minus)) {
}
delay(5);
}
// Set limit for mode
if (model < 1) {
model = 1;
}
return model;
}
void takePhoto(int value) {
switch (value) {
case 1: // NIKON
int i;
for (i = 0; i < 76; i++) {
digitalWrite(IR_EMITTER, HIGH);
delayMicroseconds(7);
digitalWrite(IR_EMITTER, LOW);
delayMicroseconds(7);
}
delay(27);
delayMicroseconds(810);
for (i = 0; i < 16; i++) {
digitalWrite(IR_EMITTER, HIGH);
delayMicroseconds(7);
digitalWrite(IR_EMITTER, LOW);
delayMicroseconds(7);
}
delayMicroseconds(1540);
for (i = 0; i < 16; i++) {
digitalWrite(IR_EMITTER, HIGH);
delayMicroseconds(7);
digitalWrite(IR_EMITTER, LOW);
delayMicroseconds(7);
}
delayMicroseconds(3545);
for (i = 0; i < 16; i++) {
digitalWrite(IR_EMITTER, HIGH);
delayMicroseconds(7);
digitalWrite(IR_EMITTER, LOW);
delayMicroseconds(7);
}
break;
case 2: // CANON
//////////////////////////
/// PUT YOUR CODE HERE ///
//////////////////////////
break;
case 3: // SONY
//////////////////////////
/// PUT YOUR CODE HERE ///
//////////////////////////
break;
case 4: // PENTAX
//////////////////////////
/// PUT YOUR CODE HERE ///
//////////////////////////
break;
case 5: // PANASONIC
//////////////////////////
/// PUT YOUR CODE HERE ///
//////////////////////////
break;
case 6: // OLYMPUS
//////////////////////////
/// PUT YOUR CODE HERE ///
//////////////////////////
break;
case 7: // LEICA
//////////////////////////
/// PUT YOUR CODE HERE ///
//////////////////////////
break;
case 8: // SIGMA
//////////////////////////
/// PUT YOUR CODE HERE ///
//////////////////////////
break;
}
}