#include <Servo.h>
// Definice pinů pro potenciometry
const int potenciometrPin1 = A0;
const int potenciometrPin2 = A1;
const int potenciometrPin3 = A2;
const int potenciometrPin4 = A3;
// Definice pinů pro servomotory
const int servoPin1 = 5; //2
const int servoPin2 = 6; //4
const int servoPin3 = 3; //7
const int servoPin4 = 9; //8
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
void setup() {
// Piny pro servomotory jsou nastaveny jako výstupy
servo1.attach(servoPin1);
servo2.attach(servoPin2);
servo3.attach(servoPin3);
servo4.attach(servoPin4);
}
void loop() {
// Přečtěte hodnoty potenciometrů
int hodnotaPotenciometru1 = analogRead(potenciometrPin1);
int hodnotaPotenciometru2 = analogRead(potenciometrPin2);
int hodnotaPotenciometru3 = analogRead(potenciometrPin3);
int hodnotaPotenciometru4 = analogRead(potenciometrPin4);
// Převedení hodnoty potenciometrů na úhly pro servomotory a zaokrouhlení na celá čísla
int uhel1 = round(map(hodnotaPotenciometru1, 0, 1023, 10, 170));
int uhel2 = round(map(hodnotaPotenciometru2, 0, 1023, 10, 170));
int uhel3 = round(map(hodnotaPotenciometru3, 0, 1023, 10, 170));
int uhel4 = round(map(hodnotaPotenciometru4, 0, 1023, 10, 170));
//int uhel1 = map(hodnotaPotenciometru1, 0, 1023, 10, 170);
//int uhel2 = map(hodnotaPotenciometru2, 0, 1023, 10, 170);
//int uhel3 = map(hodnotaPotenciometru3, 0, 1023, 10, 170);
//int uhel4 = map(hodnotaPotenciometru4, 0, 1023, 10, 170);
// Ovládání servomotorů
servo1.write(uhel1);
servo2.write(uhel2);
servo3.write(uhel3);
servo4.write(uhel4);
// Zpoždění pro stabilitu
}