summaryrefslogtreecommitdiff
path: root/autopano1d.ino
blob: 12185a7b3738ab9f5136c693e72c1745f77314f6 (plain)
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
/*
 * AutoPano1D, arduino sketch to take panorama photo driving a stepper motor and a wireless shutter
 * Copyright (C) 2018  Ludovic Pouzenc <ludovic@pouzenc.fr>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
// Tested on an Arduino Nano with IDE 1.8.5

#include <Stepper.h>
#define SERIAL_TRACE Serial.println(__FUNCTION__)

// Config
const int pictureCount = 12;
const int motorStepsPerRevolution = 200;
const int cameraStepsPerRevolution = 1000; // include external mechanic ratio
const int motorSpeed = 30; // rpm
const int cameraStabilizeDelay = 1000; // ms
const int cameraTakeDelay = 2000; // ms

// Pinout
const int buttonPin = 2;
const int shutterPin = 12;
Stepper myStepper(motorSpeed, 8, 9, 10, 11);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(shutterPin, INPUT); // Yes high-Z first, see takePic()
  myStepper.setSpeed(motorSpeed);
  Serial.begin(9600); // bauds
  ack();
}

void ack() {
  SERIAL_TRACE;
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  if ( digitalRead(buttonPin) == LOW) {
    ack();
    takePano();
    ack();
  }
}

void takePano() {
  SERIAL_TRACE;
  for ( int i=0; i<pictureCount; i++ ) {
    takePic();
    rotate();
  }
}

void takePic() {
  SERIAL_TRACE;
  // Draw current to ground for 50ms on shutterPin then return in high-Z state
  digitalWrite(shutterPin, LOW);
  pinMode(shutterPin, OUTPUT);
  delay(50);
  pinMode(shutterPin, INPUT);
  // Wait for the pic
  delay(cameraTakeDelay);
}

void rotate() {
  SERIAL_TRACE;
  myStepper.step(-cameraStepsPerRevolution/pictureCount);
  delay(cameraStabilizeDelay);
}