grazie dell'aiuto.
ho inserito le tue stringhe di codice nello sketch, sono quelle con la dicitura (aggiunta) e non rende errori però mi sfugge chi sia il buzzer: dovrei definire un piedino per il cicalino e credo che "impulsi" sia in realtà da sostituire con "Auxpulse" che sarebbe il segnale del canale aux.
prima di testarlo devo capire meglio anche perchè dovrò aprire la centralina per aggiungere i piedini per questo claxon.
questo è il codice con aggiunte le tue stringhe, le ho inserite dove mi sembrava più corretto.
//----------- signal setup -------------------------------------
#define Neutral 1445 // -- default 1500//minimum throttle forward signal or neutral position
#define Maxspeed 1932 // -- default 2000//maximum throttle forward signal
#define Antsx 1041 // -- default 1000//in front servo signal sx
#define Antdx 1968 // -- default 2000//in front servo signal dx
//----------- rear servo setup -------------------------------
#define Postsx 700 //-- default 1000//out rear servo sx end point (if inverted with postdx it reverse)
#define Postdx 2000 //-- default 2000//out rear servo dx endpoint (if inverted with postsx it reverse)
#define Center 150 //-- default 0//add or subtract your value to center steering (+- 50 or more)
//--------- user driving setup ------------------------------
#define Max_gain 550 //-- default 400//gain steering reduction width at max throttle (if work reverse add (-) before value)
#define Slowlimit 1600 //-- default 1600//slow forward percentage without endpoint correction
//------------ servo cam setup ------------------------------
#define tolerance 3 //-- default 4//servo cam vibration cutoff
#define front 10 //-- default 0//servo cam front center in moving aux position
#define Camsx -10 //--default 5// servo cam endpoint sx (reverse with camdx)
#define Camdx 180//-- default 175// servo cam endpoint dx (reverse with camsx)
#define fix 1500 //-- default 90//servo cam front center in fix aux position
//-------------led setup ------------------------------------
#define Streight 1300 //-- default 1500//neutral signal steering centered position for blinking arrow light
#define Blinkpoint 200 //-- default 300//steering value where led start to blink.
#define rearstart 1400 //-- default 1300// reverse gear light start at 1300
//----------------------------------------- program part, nothing to do here ---------------
#include <Servo.h>
Servo myservo;
Servo camservo;
#define N_STST 7 // default 7//rear steering vibration cutoff
unsigned int stSt[ N_STST ];
long toStSt = 0;
int inSt = 0;
int Tol = 0;
unsigned int auxpulse;
unsigned int Rxpulse;
unsigned int Gaspulse ;
unsigned int Gain;
unsigned int NewPos, OldPos;
unsigned int newloc, oldloc;
unsigned int Centerpos = fix ;
int led1 = 4;
int led2 = 5;
int led3 = 6;
int led4 = 3;
byte impulsi=0;//(aggiunta)
byte stato=0; //stato zero suona, stato 1 ferma il suono (aggiunta)
unsigned long intervallo=0;//(aggiunta)
void setup() {
for ( int i=0; i<N_STST; i++ ) stSt[ i ] = 0;
myservo.attach(10); //-- rear servo signal out pin 10
pinMode(8, INPUT); //-- front servo signal in pin 8
pinMode(7, INPUT); //-- throttle signal in pin 7
camservo.attach(11); //-- cam servo out pin 11
pinMode(9, INPUT); //--aux servo signal in pin 9
pinMode(led1, OUTPUT); //--led blinker dx out pin 4
pinMode(led2, OUTPUT); //--led blinker sx out pin 5
pinMode(led3, OUTPUT); //--led retro brake out pin 6
pinMode (led4, OUTPUT); //-- led maxspeed out pin 3
intervallo=millis();//(aggiunta)
}
void loop(){
auxpulse = pulseIn(9, HIGH);
Gaspulse = pulseIn(7, HIGH);
noInterrupts();
Rxpulse = pulseIn(8, HIGH);
interrupts();
delay(5);
if (Gaspulse > Slowlimit){ //-- default >// if your throttle signal is reverse must change "<"
Gain = map(Gaspulse, Slowlimit, Maxspeed, 0, Max_gain );
NewPos = map(Rxpulse, Antsx, Antdx, (Postsx + Gain), (Postdx - Gain));
}
else{
NewPos = map(Rxpulse, Antsx, Antdx, Postsx, Postdx);
}
if (abs(NewPos - OldPos)> Tol){
OldPos = NewPos;
myservo.write(NewPos + Center);}
//-- led part ----------
if (OldPos > Streight+Blinkpoint) {digitalWrite(led1, (millis() / 100) % 2); //--default 100// is led blink speed
}else digitalWrite(led1, LOW);
if (OldPos < Streight-Blinkpoint){ digitalWrite(led2, (millis() / 100) % 2); //--default 100// is led blink speed
} else digitalWrite(led2, LOW);
if (Gaspulse < rearstart){digitalWrite(led3,HIGH);
}else digitalWrite(led3, LOW);
if (Gaspulse > Maxspeed-100){digitalWrite(led4,HIGH); //-- default 100// higher values start light before maxspeed
}else digitalWrite(led4, LOW);
//-- aux cam part ----------
if(millis()-intervallo<=1000){//Se non è passato un secondo(aggiunta)
if(impulsi==4){//(aggiunta)
if(stato==0);//suona(aggiunta)
else// spegni suono(aggiunta)
impulsi=0;//(aggiunta)
stato=!stato;}// end if(aggiunta)
}else{//Se è passato un secondo(aggiunta)
impulsi=0;//(aggiunta)
intervallo=millis();}//end if(aggiunta)
if (auxpulse > 1600){//--default > 1600// change aux position but check best value will can be 1400
camservo.write(fix);
delay (4);
}else {
newloc = map(pulseIn(8, HIGH),Antsx,Antdx,Camsx,Camdx);
if(abs(newloc - oldloc) > tolerance){
oldloc = newloc;
camservo.write(newloc + front);
}
}
}
il cicalino non lo so usare, mi è capitato una sola volta di doverlo usare e credo che dovrei aggiungerlo scrivendo:
const int = 2;// piedino 2 libero al momento
pinMode(BUZZER_PIN, OUTPUT);
if condizione
digitalWrite( BUZZER_PIN, HIGH );
else
digitalWrite( BUZZER_PIN, LOW );
ho scritto Buzzer-pin per praticità ma non so ancora come aggiungerlo nel programma se sostituire a "stato", vedo cosa riesco a fare prima di testarlo sul modello.
ti ringrazio per la tua disponibilità.