Skip to content

Instantly share code, notes, and snippets.

@juliangoulding
Created August 21, 2017 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliangoulding/2151c85485bc539690d23bb33d4f271d to your computer and use it in GitHub Desktop.
Save juliangoulding/2151c85485bc539690d23bb33d4f271d to your computer and use it in GitHub Desktop.
/*
CameraSweep.ino is an adaption of the sweep example sketch for use with the timesprint app.
Writen by Julian Gouldinng
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
//25 degrees to 160 degrees is the distance my servo can move
float servostart = 1500;
float servoend = 2000;
float timeoflapse = 6; //time of final video in seconds
float fps = 30; //number of frames used per second in final video;
float intervals = 1; // time intervals between images being taken in seconds
float totalframes = 0;
float steptime = 0;
float pos = servostart; // variable to store the servo position
void setup() {
Serial.begin(9600);
totalframes = (timeoflapse * fps) * intervals; //total frames in lapse
steptime = ((totalframes/(servoend - servostart))*1000);
Serial.println (totalframes);
Serial.println (steptime);
myservo.attach(7); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = servostart; pos <= servoend; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
Serial.println(pos);
//Serial.println (steptime);
myservo.writeMicroseconds(pos); // tell servo to go to position in variable 'pos'
delay(steptime); // waits 15ms for the servo to reach the position
}
for (pos = servoend; pos >= servostart; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.writeMicroseconds(pos); // tell servo to go to position in variable 'pos'
delay(steptime); // waits 15ms for the servo to reach the position
Serial.println(pos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment