/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo horizontal;
Servo vertical;
int leftup, leftdown, rightup, rightdown;
const int startingposition = 90, min = 0, max = 180;
int z = 90, x = 90;
Servo myservo; // create servo object to control a servo
void setup() {
horizontal.attach(5); //anschluss am Arduino muss noch gewählt werden
vertical.attach(6); //anschluss am Arduino muss noch gewählt werden
horizontal.write(x);
vertical.write(z);
}
void loop() {
// Main code, Systemcode für die Ansteuerung der Servos
leftup = analogRead(A0); //anschluss am Arduino muss noch gewählt werden
leftdown = analogRead(A1); //anschluss am Arduino muss noch gewählt werden
rightup = analogRead(A2); //anschluss am Arduino muss noch gewählt werden
rightdown = analogRead(A3); //anschluss am Arduino muss noch gewählt werden
int up = (leftup + rightup) / 2;
int down = (leftdown + rightdown) / 2;
int left = (leftup + leftdown) / 2;
int right = (rightup + rightdown) / 2;
if(up > down)
{
z = z - 1;
if(z < min)
{
z = min;
}
vertical.write(z);
}
else if(up < down)
{
z = z - 1;
if(z > max)
{
z = max;
}
vertical.write(z);
}
else if (up == down)
{
}
if(right > left)
{
x = x - 1;
if(x < min)
{
x = min;
}
horizontal.write(x);
}
else if(right < left)
{
x = x -1;
if(x > max)
{
x = max;
}
horizontal.write(x);
}
else if(right == left)
{
}
delay(25);
}