-
Notifications
You must be signed in to change notification settings - Fork 0
/
lumix_intervalometer.ino
109 lines (88 loc) · 2.69 KB
/
lumix_intervalometer.ino
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
/*
Panasonic/Lumix Intervalometer
Triggers shutter via remote control port (coupled via optocouplers).
*/
/***** BEGIN IO initialization *****/
const int inSwitch = 12; // push button to change the running state with
const int outRunning = 11; // LED to display the running state (on when running)
const int outAction = 13; // LED to display the action state (on when triggering)
const int outFocus = 10; // optocoupler to trigger focus
const int outShutter = 9; // optocoupler to trigger shutter
// pins 0-7 are used as input switches for timing
void setAsInput(int pin) {
pinMode(pin, INPUT);
digitalWrite(pin, HIGH); // turn on Atmega's pullup resistor
}
void setup() {
setAsInput(inSwitch);
for (int i = 0; i < 8; i++) {
setAsInput(i);
}
pinMode(outRunning, OUTPUT);
pinMode(outAction, OUTPUT);
pinMode(outFocus, OUTPUT);
pinMode(outShutter, OUTPUT);
}
/***** END IO initialization *****/
/***** BEGIN loop *****/
unsigned long curTime = 0;
unsigned long nextActiveChangeTime = 0;
const int actionDuration = 500;
void loop() {
curTime = millis();
checkRunning();
performAction();
}
/***** END loop *****/
/***** BEGIN switch to choose between running/sleeping *****/
boolean running = false; // are we intervalometering?
int prevSwitch = HIGH;
int debounceSwitch = HIGH;
unsigned long prevSwitchDebounceTime = 0;
const int debounceInterval = 10;
void checkRunning() {
int curSwitch = digitalRead(inSwitch);
// debounce button
if (curSwitch != debounceSwitch) {
prevSwitchDebounceTime = curTime;
}
debounceSwitch = curSwitch;
if (curTime - prevSwitchDebounceTime > debounceInterval) {
// act upon fresh button presses
if (prevSwitch == HIGH && curSwitch == LOW) {
running = !running;
digitalWrite(outRunning, running);
if (running) {
nextActiveChangeTime = curTime;
}
}
prevSwitch = curSwitch;
}
}
/***** END running switch *****/
/***** BEGIN action stuff *****/
unsigned long actionInterval() {
unsigned long interval = 0;
for (int i = 0; i < 8; i++) {
if (digitalRead(i) == LOW) {
interval += 1 << i;
}
}
if (interval > 0) {
interval = interval * 1000 - actionDuration;
}
return interval;
}
boolean active = false; // are we executing the action?
void performAction() {
if (curTime >= nextActiveChangeTime) {
unsigned long curActionInterval = actionInterval();
if ((running && curActionInterval > 0) || active) {
active = !active;
digitalWrite(outAction, active);
digitalWrite(outShutter, active);
}
nextActiveChangeTime = curTime + (active ? actionDuration : curActionInterval);
}
}
/***** END action stuff *****/