Created
December 16, 2012 20:24
-
-
Save sm00th/4312484 to your computer and use it in GitHub Desktop.
This file contains 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
#include <Servo.h> | |
#define MIN_Y 90 | |
#define MAX_Y 180 | |
#define MIN_X 0 | |
#define MAX_X 180 | |
Servo tilt; | |
Servo pan; | |
int curX = MAX_X/2; | |
int curY = MIN_Y; | |
void setup() { | |
Serial.begin( 115200 ); | |
pan.attach( 11 ); | |
tilt.attach( 12 ); | |
tilt.write( curX ); | |
pan.write( curY ); | |
} | |
void loop() { | |
while( Serial.available() == 0 ); | |
int c = Serial.read(); | |
int x,y; | |
Serial.flush(); | |
x = ( c % 10 ) - 2; | |
y = ( c / 10 ) - 2; | |
curX += x; | |
curY += y; | |
if( curX > MAX_X ) | |
curX = MAX_X; | |
if( curY > MAX_Y ) | |
curY = MAX_Y; | |
if( curX < MIN_X ) | |
curX = MIN_X; | |
if( curY < MIN_Y ) | |
curY = MIN_Y; | |
tilt.write( curX ); | |
pan.write( curY ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment