/**************
Name: Ivan Ivanov
Datum: 30.04.2024
Übung: Servomotor Joystick
**********/
#include <Servo.h>
// Pinbelegungen
int joystickPin = A0; // Analoger Pin des Joysticks
int servoPin = 9; // Pin des Servos
// Minimale und maximale Werte
int joystickMin = 0;
int joystickMax = 1023;
int servoMin = 0; // Minimum Servo Position
int servoMax = 180; // Maximum Servo Position
Servo myServo;
void setup()
{
myServo.attach(servoPin); // Servo an Pin 9 anschließen
Serial.begin(9600);
}
void loop()
{
int joystickValue = analogRead(joystickPin); // joystick value lesen
int servoWinkel = map(joystickValue, joystickMin, joystickMax, servoMin, servoMax); // wandelt sie den analogen Joystick Wert zwischen 0 und 1023 in den entsprechenden Servo Winkel zwischen 0 und 180 Grad um.
myServo.write(servoWinkel); // Servo auf den berechneten Winkel setzen
delay(100);
Serial.println(servoWinkel); // Potentiometer wert lesen
}