/* 2 Axis time lapse dolly software Written by JD Ritchey 12-12-13 Big thanks to everyone in the arduino community who wrote libraries and functions that you see within!!! */ #include #include #include LiquidCrystal lcd(12, 11, 2, 3, 4, 5); Servo servo1; const int pin0 = A5; const int pin1 = A4; const int pin2 = A3; const int reedPin = 7; const int focusPin = 8; const int shutterPin = 6; const int times[16] = { 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 60, 90, 120, 600}; const int speeds[16] = { 1, 2, 4, 8, 15, 30, 60, 100, 100, 100, 100, 100, 100, 100, 100, 100}; long previousMillis = 0; long day = 86400000; // 86400000 milliseconds in a day long hour = 3600000; // 3600000 milliseconds in an hour long minute = 60000; // 60000 milliseconds in a minute long second = 1000; // 1000 milliseconds in a second int shotCount = 0; long lastStopMillis = 0; int motorSpeed = 6000; //maximum steps per second int motorAccel = 800; //steps/second/second to accelerate int motorDirPin = 10; //digital pin 2 int motorStepPin = 13; //digital pin 3 AccelStepper stepper(1, motorStepPin, motorDirPin); int snap1=0; //===============================Setup=========================================// void setup() { servo1.attach(9); Serial.begin(9600); servo1.writeMicroseconds(1500); pinMode(reedPin, INPUT); lcd.begin(16, 2); pinMode(shutterPin, OUTPUT); pinMode(focusPin, OUTPUT); stepper.setMaxSpeed(motorSpeed); stepper.setSpeed(motorSpeed); stepper.setAcceleration(motorAccel); digitalWrite(shutterPin, LOW); digitalWrite(focusPin, LOW); } //===============================MainLoop=========================================// void loop() { long timeNow = millis()-lastStopMillis; int days = timeNow / day ; int hours = (timeNow % day) / hour; int minutes = ((timeNow % day) % hour) / minute ; int seconds = (((timeNow % day) % hour) % minute) / second; int speedValue = analogRead(pin1); int speedDisplay = map(speedValue, 0, 1023, -8, 9); int sensorValue = analogRead(pin0); int delayInterval = map(sensorValue, 0, 1023, 0, 15); int stepperValue = analogRead(pin2); int stepperMove = map(stepperValue, 0, 1023, 10, 250); stepper.run(); int reedstate = digitalRead(reedPin); if(reedstate == LOW) { lcd.setCursor(0,0); lcd.print("WAIT"); lcd.setCursor(8,0); lcd.print("Delay:"); lcd.print(times[delayInterval]); lcd.print(" "); lcd.setCursor(0,1); lcd.print(hours); lcd.print(":"); lcd.print(minutes); lcd.print(":"); lcd.print(seconds); lcd.print(" "); lcd.setCursor(7,1); lcd.print(" Pic:"); lcd.print(shotCount); lcd.print(" "); unsigned long currentMillis = millis(); if(currentMillis - previousMillis > (1000*times[delayInterval]) && snap1 == 0) { snap(); } else if(currentMillis - previousMillis > ((1000*times[delayInterval])+1000)){ stepper.move(stepperMove); makeMove(speedDisplay); previousMillis = currentMillis; snap1 = 0; } } else { servo1.writeMicroseconds(1500); stepper.move(0); lcd.setCursor(0,0); lcd.print("STOP "); lcd.setCursor(8,0); lcd.print("Delay:"); lcd.print(times[delayInterval]); lcd.print(" "); lcd.setCursor(8,1); lcd.print("Speed:"); lcd.print(speedDisplay); lcd.print(" "); lcd.setCursor(0,1); lcd.print("Pan:"); lcd.print(stepperMove); if (stepperMove <= 99); lcd.print(" "); shotCount=0; lastStopMillis = millis(); delay(10); } } //===============================Functions=========================================// void makeMove(int speedStatus){ lcd.setCursor(0,0); lcd.print("MOVE"); lcd.setCursor(8,0); lcd.print("Speed:"); lcd.print(speedStatus); if (speedStatus > 0 && speedStatus != 8) { for(int speed1 = 1500; speed1 <=1800; speed1 += 10){ servo1.writeMicroseconds(speed1); delay(speeds[abs(speedStatus)]); } servo1.writeMicroseconds(1500); } else if (speedStatus < 0 && speedStatus != -8) { for(int speed7 = 1500; speed7 >=1200; speed7 -= 10) { servo1.writeMicroseconds(speed7); delay(speeds[abs(speedStatus)]); } servo1.writeMicroseconds(1500); } else if (speedStatus == -8) { servo1.writeMicroseconds(1200); } else if (speedStatus == 0) { servo1.writeMicroseconds(1500); } else if (speedStatus == 8) { servo1.writeMicroseconds(1800); } } void snap(){ lcd.setCursor(0,0); lcd.print("SNAP"); digitalWrite(focusPin, HIGH); delay(200); digitalWrite(shutterPin, HIGH); delay(100); digitalWrite(shutterPin, LOW); digitalWrite(focusPin, LOW); snap1 = 1; shotCount++; }