Ciao a Tutti, sono nuovo e molto poco esperto di Arduino e programmazione. Sto utilizzando Arduino Uno per comandare 3 servo tramite 3 potenziometri, per remotare il Pan, Tilt e Focus di una videocamera.
Ho trovato in rete questo progetto (comanda un servo con un potenziometro) che ho provato e funziona benissimo.
Quello che vorrei realizzare è di moltiplicare per 3 il tutto.
Ho cercato di scrivere lo sketch attingendo a quelli indicati nel post precedente:
#include <Servo.h>
Servo servo1; // create servo object to control a servo1
int potpin1 = 0; // analog pin used to connect the potentiometer 1
int val1; // variable to read the value from the analog pin (1024 steps from 0 to 1023)
Servo servo2; // create servo object to control a servo2
int potpin2 = 1; // analog pin used to connect the potentiometer 2
int val2; // variable to read the value from the analog pin (1024 steps from 0 to 1023)
Servo servo3; // create servo object to control a servo3
int potpin3 = 2; // analog pin used to connect the potentiometer 3
int val3; // variable to read the value from the analog pin (1024 steps from 0 to 1023)
void setup()
{
Serial.begin(9600); // start serial communication
servo1.attach(8); // attaches the servo on pin 8 to the servo1 object
servo2.attach(9); // attaches the servo on pin 9 to the servo2 object
servo3.attach(10); // attaches the servo on pin 10 to the servo3 object
}
void loop()
{
val1 = analogRead(potpin1);
int oneturn = val1 / 6; // 6-Turn-Servo uses only one turn (can also be more or less, depending on your lens and gear wheel diameter)
val2 = analogRead(potpin2);
val3 = analogRead(potpin3);
int servoposition = oneturn + 1001; // translates 1024 poti steps into val / 6 servo steps
Serial.println(servoposition); // for test purposes, you can see the poti values in the serial monitor
servo1.writeMicroseconds(servoposition); // servo gets position information
servo2.writeMicroseconds(servoposition); // servo gets position information
servo3.writeMicroseconds(servoposition); // servo gets position information
}
purtroppo quesllo che ho ottenuto è che ogni potenziometro comanda i 3 servo contemporaneamente.
Qualcuno mi può correggere?
Premetto che i servo da comandare non sono dei semplici servo che devono girare di 180° ma dei verricelli che possono compiere fino ad un massimo di 6 giri.
Grazie a tutti