Ho constatato che e' un problema della libreria di arduino.
Caricandone una diversa da gestore librerie le cose cambiano.
Prova questo codice
Codice:
#define Neutral 1500 // -- minimum forward signal
#define Maxspeed 2000 // -- maximum forward signal
#define Antsx 1000 // -- in front servo signal sx
#define Antdx 2000 // -- in front servo signal dx
#define Postsx 1000 // out rear servo sx endpoint if inverted with postdx it reverse
#define Postdx 2000 //-- out rear servo dx endpoint if inverted with postsx it reverse
#define Center 0 //-- add or subtract xx value to center steering
#define Tolerance 1 //-- if poor quality servo vibrates try 5
#define Max_gain 950 //-- gain steering reduction by throttle if reverse add -
#define Slowlimit 1800 //-- slow forward without endpoint correction
#include <MobaTools.h>
MoToServo myservo;
unsigned int Rxpulse;
unsigned int Gaspulse ;
unsigned int Gain;
signed int NewPos, OldPos;
int Stato;
int Stato_Led=0;
boolean Cmd_Led = false;
int Ledpin=13;
int Led=0;
int Tol_cont=0;
int Media_GAS=0;
int Media_RX=0;
void setup() {
pinMode(7, INPUT); //-- throttle signal in pin
pinMode(8, INPUT); //-- front servo signal in pin
pinMode(Cmd_Led, OUTPUT);
myservo.attach(10); //-- rear servo signal out pin
myservo.setSpeed( 48 );
Stato = 0;
}
void loop() {
if (Stato == 0) {
//lettura
Rxpulse = pulseIn(8, HIGH);
Gaspulse = pulseIn(7, HIGH);
}
if (Stato == 1) {
//Calcolo
if (Gaspulse > Slowlimit) {
Gain = map(Gaspulse, Slowlimit, Maxspeed, 0, Max_gain );
NewPos = map(Rxpulse, Antsx, Antdx, (Postsx + Gain), (Postdx - Gain));
Led=1;
}
else {
NewPos = map(Rxpulse, Antsx, Antdx, Postsx, Postdx);
Led=2;
}
}
if (Stato == 2) {
//scrittura
if (abs(NewPos - OldPos) > Tolerance) {
myservo.write(NewPos + Center);
OldPos=NewPos;
}
}
// Incrementa stato per il prossimo loop
++Stato;
// Incrementa tempo led per il prossimo loop
++Stato_Led;
if (Stato == 3) {
// riparte da 0
Stato = 0;
}
//ritardo esecuzione cicli/stati
delay(1);
if (Led == 1) {
//led veloce
if (Stato_Led>20) {
Cmd_Led= !Cmd_Led;
Stato_Led=0;
}
digitalWrite(Ledpin, Cmd_Led);
}
if (Led == 2) {
//led lento
if (Stato_Led>60) {
Cmd_Led= !Cmd_Led;
Stato_Led=0;
}
digitalWrite(Ledpin, Cmd_Led);
}
}
Tolerance e' a 1, prova solo a modificare la linea
myservo.setSpeed( 48 );
variando il numero 48 tra 1 e 256
La libreria si chiama MobaTools e credo che sia questa la soluzione