Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 298 lines (231 sloc) 4.959 kB
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
1 // Intervalometer and dolly motor controller
2 // Olli-Pekka Heinisuo 2011
3 // Licensed under MIT license, see LICENSE.txt
4 // This is experimental version, change to master branch if you want normal version
5
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
6 /*
7 This version does not include any motor functionality,
8 just plain, enchanced intervalometer! (for example star timelapses)
9 BULB-mode required, this version was made very long exposures in mind:
10 max interval 999 secs, max exposure time 999 secs
11 */
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
12
13 // LCD library
14 #include <LiquidCrystal.h>
15 // These pins are not used by Adafruit motor shield if it's using only motor 1
16 LiquidCrystal lcd(10, 9, 5, 3, 2, 14);
17
18 // pin that will trigger the camera
19 #define CAMERA_PIN 13
20
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
21 // "exposing" or not, if false, sends pulse to the optocoupler
22 // which triggers the camera
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
23 bool exposing = false;
24
25 int c,s,t,r,e,b,m,p,n = 0;
26 int pause;
27 int counter = 0;
28 int interval;
29 int exposure;
30 int state;
31 int divi;
32 unsigned long time = 0;
33
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
34 void setup() {
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
35
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
36 pinMode(13, OUTPUT);
37 pinMode(A5, INPUT); // pins for the buttons
38 pinMode(A4, INPUT);
39 pinMode(A3, INPUT);
40 pinMode(CAMERA_PIN, OUTPUT); // to the optocoupler
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
41
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
42 // set up the LCD's number of columns and rows:
43 lcd.begin(16, 2);
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
44 }
45
46 // These functions return a value when the corresponding button is pressed
47 // 1,8 kohm resistors were used between 6 buttons (7 resistors)
48 // More info: http://tronixstuff.wordpress.com/2011/01/11/tutorial-using-analog-input-for-multiple-buttons/
49 //
50 // Switches:
51 // 1 kohm resistors were used with 2 switches, total 6 resistors
52
53 // Reset button
54
55 int resetButton(int pin) {
56
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
57 c=analogRead(pin);
58
59 if (c<160 && c>100) {
60 r = 1; // reset button
61 }
62 return r;
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
63 }
64
65 /* coming later, sensor buttons for dolly
66 int shutDown(int pin) {
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
67
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
68 c=analogRead(pin);
69
70 if (c< && c>)
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
71 {
72 r = 1; // stop&reset to prevent any damage
73 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
74 return r;
75 }
76 */
77
78 // interval time
79
80 int dig1Button(int pin) {
81
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
82 c=analogRead(pin);
83
84 if (c>160 && c<180)
85 {
86 delay(250); // if not set, value will increment as long as the button
87 // was pressed and we don't want that to happen (about 100-200 ms)
88 ++e;
89 }
90 if (e < 999) {
91 return e;
92 }
93 else {
94 return e=0;
95 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
96 }
97
98 // interval time
99
100 int dig2Button(int pin) {
101
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
102 c=analogRead(pin);
103
104 if (c>180 && c<210)
105 {
106 delay(250);
107 --e;
108 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
109 if (e > 0) {
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
110 return e;
111 }
112 else {
113 return e=0;
114 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
115 }
116
117 // exposure time
118
119 int dig3Button(int pin) {
120
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
121 c=analogRead(pin);
122
123 if (c>330 && c<370)
124 {
125 delay(250);
126 ++n;
127 }
128 if (n < 999) {
129 return n;
130 }
131 else {
132 return n=0;
133 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
134 }
135
136 // exposure time
137
138 int dig4Button(int pin) {
139
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
140 c=analogRead(pin);
141
142 if (c>240 && c<270)
143 {
144 delay(250);
145 --n;
146 }
147 if (n > 0) {
148 return n;
149 }
150 else {
151 return n=0;
152 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
153 }
154
155 // Start & stop
156
157 int startButton(int pin) {
158
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
159 c=analogRead(pin);
160
161 if (c>500 && c<600) {
162 delay(250);
163 s++;
164 }
165 if (s <= 1) {
166 return s;
167 }
168 else if (s > 1) {
169 return s=0;
170 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
171 }
172
173 /* select time range, default (0) is 0,0 - 9,9 seconds, (1) is 0-99 seconds
174
175 int timingSwitch(int pin) {
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
176
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
177 c=analogRead(pin);
178
179 if (c>450 && c < 550) {
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
180 return t=1;
181 }
182 else if (c < 450 && c>300) {
183 return t=0;
184 }
185 else if (c == 0) {
186 return t=2;
187 }
188 else {
189 return t=0;
190 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
191 }
192
193 // switch for choosing motor behavior: if on, motor moves without pauses, if off motor pauses when pic is taken
194
195 int motorSwitch(int pin) {
196
197 c=analogRead(pin);
198
199 if (c>450 && c < 550) {
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
200 return m=1;
201 }
202 else if (c < 450 && c>300) {
203 return m=0;
204 }
205 else if (c == 0) {
206 return m=2;
207 }
208 else {
209 return m=0;
210 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
211 }
212
213 */
214
215 // This is where the magic happens
216
217 void loop() {
218
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
219 // If the reset button is pressed -> pause + every variable
220 // returns to their default values
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
221
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
222 if (r == 1 ) {
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
223
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
224 digitalWrite(CAMERA_PIN, LOW);
225 s = 0;
226 r = 0;
227 b = 0;
228 e = 0;
229 p = 0;
230 n = 0;
231 counter = 0;
232 lcd.clear();
233 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
234
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
235 // constantly updating the values enables the possibility
236 // to modify interval time on the fly
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
237
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
238 e = dig1Button(5); // interval
239 n = dig3Button(5); // exposure
240 e = dig2Button(5); // interval
241 n = dig4Button(5); // exposure
242 s = startButton(5); // start
243 r = resetButton(5); // reset (and stop)
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
244
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
245 // These are for LCD-display, type 16x2
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
246
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
247 // Interval
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
248
249
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
250 lcd.setCursor(0, 0);
251 lcd.print("Int:");
252 lcd.setCursor(4, 0);
253 lcd.print(e);
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
254
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
255 // Exposure time
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
256
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
257 lcd.setCursor(8, 0);
258 lcd.print("Exp:");
259 lcd.setCursor(12, 0);
260 lcd.print(n);
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
261
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
262 // Picture counter
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
263
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
264 lcd.setCursor(9, 1);
265 lcd.print("No:");
266 lcd.setCursor(12, 1);
267 lcd.print(counter);
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
268
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
269 if (s == 1) {
270
271 interval = e*1000; // full seconds, values from 0 to 999 seconds accepted
272 exposure = n*1000;
273
274 if (exposing == false) {
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
275
d30a4e1 @skvark removed unnecessary comments, reindented the code, line lengthis now …
authored
276 // enable optocoupler
277 digitalWrite(CAMERA_PIN, HIGH);
278 // set state 'high' for the pulse statement
279 state = HIGH;
280 time = millis();
281 exposing = true;
282 counter++; // counter, if LCD is in use
283 }
284
285 else if ( millis() - time >= exposure && state == HIGH && exposing == true)
286 {
287 digitalWrite(CAMERA_PIN, LOW);
288 state = LOW;
289 }
290
291 // sets the exposing flag to false when interval time has passed
292
293 else if ( millis() - time >= interval && exposing == true)
294 {
295 exposing = false;
296 }
297 }
d12d61a @skvark New version _static_, no motor, but BULB-mode required to work
authored
298 }
Something went wrong with that request. Please try again.