Tu me dis si je modifie correctement le code ou pas.
Ici en rouge pas de modif sur les déclarations des pins
////////////////////////////////////////////////////////////////////////////////
// DECLARATIONS
////////////////////////////////////////////////////////////////////////////////
/* VNH2SP30 pin definitions*/ // MV
int inApin[3] = {8, 9, 12}; // INA: Clockwise input // TC
int inBpin[3] = {7, 4, 11}; // INB: Counter-clockwise input // TC
int pwmpin[3] = {5, 6, 10}; // PWM input // MV
int cspin[2] = {2, 3}; // CS: Current sense ANALOG input // MV
int enpin[3] = {0, 1, 2}; // EN: Status of switches output (Analog pin) // MV
int statpin = 13; //not explained by Sparkfun
/* init position value*/
int DataValueL=512; //middle position 0-1024
int DataValueR=512; //middle position 0-1024
int DataValueM=512; //middle position 0-1024 // MV
Ensuite j'intègre le code INITIALIZATION en remplacement de mon code de base
////////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
////////////////////////////////////////////////////////////////////////////////
void setup()
{
// serial initialization
Serial.begin(115200);
// initialization of Arduino's pins
pinMode(statpin, OUTPUT); //not explained by Sparkfun
digitalWrite(statpin, LOW);
for (int i=0; i<3; i++) // MV
{
pinMode(inApin[i], OUTPUT);
pinMode(inBpin[i], OUTPUT);
pinMode(pwmpin[i], OUTPUT);
}
// Initialize braked for motor
for (int i=0; i<3; i++) // MV
{
digitalWrite(inApin[i], LOW);
digitalWrite(inBpin[i], LOW);
}
}
Puis ca se complique je suis perdu...
Dois je ajouter cette ligne ?
void loop()
{
int sensorL,sensorR, sensorM; // MV
readSerialData(); // DataValueR & L contain the last order received (if there is no newer received, the last is kept)
// the previous order will still be used by the PID regulation MotorMotion Function
sensorR = analogRead(potR); // range 0-1024
sensorL = analogRead(potL); // range 0-1024
sensorM = analogRead(potM); // range 0-1024 // MV
analogWriteD9(sensor);
motorMotion(motRight,sensorR,DataValueR);
motorMotion(motLeft,sensorL,DataValueL);
motorMotion(motMedium,sensorM,DataValueM); // MV
}
Est ce que du fait que le PWM ne varie plus entre 0 et 255 je dois changer qq chose dans "l'asservissement" ici :
// PID : calculates speed according to distance
pwm=255;
if (gap>25) pwm=50; //TC
if (gap>125) pwm=150; //TC
if (gap>225) pwm=250; //TC
pwm=map(pwm, 0, 255, 0, pwmMax); //adjust the value according to pwmMax for mechanical debugging purpose !
Merci d'avance.