Skip to content

Instantly share code, notes, and snippets.

@uktechreviews
Created April 6, 2016 19:21
Show Gist options
  • Save uktechreviews/c923aa263017419d8c1b9eb238f72986 to your computer and use it in GitHub Desktop.
Save uktechreviews/c923aa263017419d8c1b9eb238f72986 to your computer and use it in GitHub Desktop.
time lapse Arduino code
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo horizontal;
Servo vert;
// create servo object to control a servo
// a maximum of eight servo objects can be created
int posx = 0; // variable to store the servo position in the horizontal direction
int orange = 13;
int green = 12;
int buzzer = 11;
int buttonPin = 6;
int buttonState=0;
void setup()
{
pinMode(orange, OUTPUT);
pinMode(green, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(green,HIGH);
digitalWrite(orange,HIGH);
digitalWrite(buzzer,HIGH);
delay(1000);
digitalWrite(orange,LOW);
digitalWrite(buzzer,LOW);
delay(1000);
digitalWrite(orange,HIGH);
delay(1000);
digitalWrite(orange,LOW);
delay(1000);
digitalWrite(orange,HIGH);
delay(1000);
digitalWrite(orange,LOW);
delay(1000);
digitalWrite(orange,HIGH);
delay(1000);
digitalWrite(orange,LOW);
delay(1000);
horizontal.attach(3); // attaches the servo on pin 9 to the servo object
vert.attach(4);
vert.write(65);
delay(500);
horizontal.write(0);
vert.write(60);
delay(500);
horizontal.write(100);
vert.write(180);
delay(500);
vert.write(60);
delay(500);
horizontal.write(100);
vert.write(180);
delay(500);
digitalWrite(orange,HIGH);
delay(500);
digitalWrite(orange,LOW);
delay(500);
}
void loop()
{
for(posx = 60; posx < 180; posx += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
buttonState=digitalRead(buttonPin);
if (buttonState == HIGH){
horizontal.write(0);
delay(500);
horizontal.write(60);
}
digitalWrite(orange,HIGH);
delay(1000);
vert.write(posx); // tell servo to go to position in variable 'pos'
digitalWrite(orange,LOW);
delay(6000); // waits 15ms for the servo to reach the position
}
for(posx = 180; posx>=60; posx-=1) // goes from 180 degrees to 0 degrees
{ // in steps of 1 degree
buttonState=digitalRead(buttonPin);
if (buttonState == HIGH){
horizontal.write(0);
delay(500);
horizontal.write(60);
}
digitalWrite(orange,HIGH);
delay(1000);
vert.write(posx); // tell servo to go to position in variable 'pos'
digitalWrite(orange,LOW);
delay(6000); // waits 15ms for the servo to reach the position
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment