
This is really not much of an Arduino project (it only involves hooking up two servos and controlling it via serial port to respond to U,D,L,R,C for Up, Down, Left, Right, and Center). But it is pretty cool to be able to control my home webcam without having to mess with DynamicIP, port forwarding, etc because Skype does all that for you.
If you ever want to have a remote pan/tilt webcam and do not want to setup a home webserver, this maybe of interest to you.
Sorry, it's windows only, but C# source code is included and Skype API is available for Java and Python, so it should be easily ported.
/*
======================================
SkyDuino Sketch - Hari Wiguna 2010
======================================
*/
#include <Servo.h>
Servo xServo;
Servo yServo;
int stepSize = 10;
const int xInit = 90;
const int yInit = 90;
const int xMin = 0;
const int xMax = 180;
const int yMin = 0;
const int yMax = 180;
int x = xInit;
int y = yInit;
int xNew = x;
int yNew = y;
void setup()
{
Serial.begin(9600);
//establishContact(); // send a byte to establish contact until receiver responds
xServo.attach(5); // attaches the servo on pin 9 to the servo object
yServo.attach(6); // attaches the servo on pin 9 to the servo object
delay(1000);
MoveServo(xServo, xServo.read(), x);
MoveServo(yServo, yServo.read(), y);
delay(100);
pinMode(11, OUTPUT);
}
void Beep()
{
digitalWrite(11,HIGH);
delay(250);
digitalWrite(11,LOW);
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
Beep();
char msg = Serial.read();
if (msg == 'C') {xNew=xInit; yNew=yInit;}
if (msg == 'R') xNew = x - stepSize;
if (msg == 'L') xNew = x + stepSize;
if (msg == 'D') yNew = y - stepSize;
if (msg == 'U') yNew = y + stepSize;
xNew = constrain(xNew, xMin, xMax);
yNew = constrain(yNew, yMin, yMax);
}
MoveServo(xServo, x, xNew);
MoveServo(yServo, y, yNew);
x = xNew;
y = yNew;
}
void MoveServo(Servo servo, int moveFrom, int moveTo)
{
if (moveFrom <= moveTo)
{
for (int c=moveFrom; c<=moveTo; c++)
{
servo.write(c);
delay(50);
}
}
if (moveFrom > moveTo)
{
for (int c=moveFrom; c>=moveTo; c--)
{
servo.write(c);
delay(50);
}
}
}