Skip to content

Instantly share code, notes, and snippets.

@sfambach
Created June 30, 2019 22:13
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 sfambach/e0921d8f97bdc2b470a9045982c66d6b to your computer and use it in GitHub Desktop.
Save sfambach/e0921d8f97bdc2b470a9045982c66d6b to your computer and use it in GitHub Desktop.
Controlling a Pan Tilt with help of a Joystick
/***********************************************
* Control pan/tilt with joystick
* www.fambach.net
* GPL v2
*
* you can influence the drive of the servos by adjusting the min and max values.
*/
#include<Servo.h>
#define JOYX A0
#define JOYY A1
Servo servox;
Servo servoy;
void setup(){
Serial.begin(115200);
servox.attach(9);
servoy.attach(10);
}
int xmin = 20, xmax = 130, ymin = 0, ymax = 125, step = 10;
void loop(){
int ax = analogRead(JOYX);
int ay = analogRead(JOYY);
int x = map(ax, 1024,0, xmin, xmax);
int y = map(ay, 0,1024, ymin, ymax);
servox.write(x);
servoy.write(y);
Serial.print("aX: ");
Serial.print(ax);
Serial.print(" aY: ");
Serial.print(ay);
Serial.print(" sX: ");
Serial.print(x);
Serial.print(" sY: ");
Serial.print(y);
Serial.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment