Created
June 30, 2019 22:13
-
-
Save sfambach/e0921d8f97bdc2b470a9045982c66d6b to your computer and use it in GitHub Desktop.
Controlling a Pan Tilt with help of a Joystick
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
/*********************************************** | |
* 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