Forked from KyleMartinTech/Rotating GoPro Servo Base
Last active
March 22, 2018 17:58
-
-
Save KonradIT/3ae7b68498122f71f49c812400205588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is a forked and modified version of Kyle Martin's Rotating Servo Base code. You can view the original source code here: https://gist.github.com/KyleMartinTech/0007b7d093c94b4556c09d4de82eff5c | |
I added the following features to the code: | |
- Send command to Stop the video capture / timelapse capture when the Servo motor stops | |
- Send command to start the timelapse capture when the Servo motor starts moving again | |
Need to add: | |
- Keep Alive background thread (or send after every servo movement) | |
- Wake On Lan to allow for powering off and on when the room is empty | |
I used commands for HERO 4, 5, 6, Session from my API: http://github.com/konradit/goprowifihack | |
--- | |
*/ | |
//This is the code to go along with this video: https://youtu.be/xdurnklqtGM | |
//Program uses a Motion sensor and sound sensor to only rotate the camera while there is someone in the room. | |
#include <Servo.h> | |
#include <arduino.h> | |
#include <Ethernet.h> | |
Servo myservo1; | |
Servo myservo2; | |
int pos1 = 0; // variable to store the servo position | |
int pos2 = 45; // servo 2 positions, the range of motion of this servo will be 1/2 that of the rotation servo | |
const int soundInput = 4; | |
const int motionInput = 3; | |
const int LED = 2; | |
int timer = 0; | |
int direction = 0; | |
int count = 0; | |
//gopro config | |
IPAddress server(10,5,5,9); | |
EthernetClient httpClient; | |
void setup() { | |
pinMode (soundInput, INPUT); | |
pinMode (motionInput, INPUT); | |
pinMode (LED, OUTPUT); | |
myservo1.attach(9); // attaches the servo on pin 9 to the servo object | |
myservo2.attach(10); // attaches the second servo to pin 10 | |
} | |
void loop() { | |
while(direction == 0 && pos1 < 180){ | |
digitalWrite(LED,HIGH); | |
if (digitalRead(soundInput) == HIGH){ | |
timer = 0; | |
} | |
myservo1.write(pos1); | |
myservo2.write(pos2); | |
pos1++; | |
pos2 = (pos1/2)+45; | |
while((timer<10000 || digitalRead(motionInput) == HIGH) && count < 1000){ | |
if (digitalRead(soundInput) == HIGH){ | |
timer = 0; | |
if (client.connect(server, 80)) { | |
client.println("GET gp/gpControl/command/shutter?p=0 HTTP/1.0"); | |
client.println(); | |
} | |
else { | |
Serial.println("Connection failed"); | |
} | |
} | |
delay(1); | |
count++; | |
timer++; | |
} | |
count = 0; | |
while(timer>=10000 && digitalRead(motionInput) == LOW){ | |
digitalWrite(LED,LOW); | |
if (digitalRead(soundInput) == HIGH){ | |
timer = 0; | |
if (client.connect(server, 80)) { | |
client.println("GET gp/gpControl/command/shutter?p=0 HTTP/1.0"); | |
client.println(); | |
} | |
else { | |
Serial.println("Connection failed"); | |
} | |
} | |
delay(1); | |
if (client.connect(server, 80)) { | |
client.println("GET gp/gpControl/command/shutter?p=1 HTTP/1.0"); | |
client.println(); | |
} | |
else { | |
Serial.println("Connection failed"); | |
} | |
} | |
} | |
direction = 1; | |
while(direction = 1 && pos1 <= 0){ | |
digitalWrite(LED,HIGH); | |
if (digitalRead(soundInput) == HIGH){ | |
timer = 0; | |
if (client.connect(server, 80)) { | |
client.println("GET gp/gpControl/command/shutter?p=0 HTTP/1.0"); | |
client.println(); | |
} | |
else { | |
Serial.println("Connection failed"); | |
} | |
} | |
myservo1.write(pos1); | |
myservo2.write(pos2); | |
pos1--; | |
pos2 = (pos1/2)+45; | |
while((timer<10000 || digitalRead(motionInput) == HIGH) && count < 1000){ | |
if (digitalRead(soundInput) == HIGH){ | |
timer = 0; | |
if (client.connect(server, 80)) { | |
client.println("GET gp/gpControl/command/shutter?p=0 HTTP/1.0"); | |
client.println(); | |
} | |
else { | |
Serial.println("Connection failed"); | |
} | |
} | |
delay(1); | |
count++; | |
timer++; | |
} | |
count = 0; | |
while(timer>=10000 && digitalRead(motionInput) == LOW){ | |
digitalWrite(LED,LOW); | |
if (digitalRead(soundInput) == HIGH){ | |
if (client.connect(server, 80)) { | |
client.println("GET gp/gpControl/command/shutter?p=0 HTTP/1.0"); | |
client.println(); | |
} | |
else { | |
Serial.println("Connection failed"); | |
} | |
timer = 0; | |
} | |
delay(1); | |
if (client.connect(server, 80)) { | |
client.println("GET gp/gpControl/command/shutter?p=1 HTTP/1.0"); | |
client.println(); | |
} | |
else { | |
Serial.println("Connection failed"); | |
} | |
} | |
} | |
direction = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment