Pensez-vous que mon programme va marcher?

D'accord, je comprend!

Dans ce cas, mon nouveau code devient ceci?

const int pingPin = 7;
int moteur= 3;
#include <Servo.h> 
int rouge = 6;
int vert = 5;
int bleu= 4;
Servo myservo;
int pos = 0;
const int MaxSonar = 1; 
long anVolt, inches, cm2;
int sum=0;
int avgrange=60;





void setup() {
  

pinMode(moteur, OUTPUT);
pinMode(rouge, OUTPUT);
pinMode(vert,OUTPUT);
pinMode(bleu,OUTPUT);
myservo.attach(9);
pinMode(MaxSonar,INPUT);

}

long int acquisitionPing(void){
    long int duration;

    pinMode(pingPin, OUTPUT);
    digitalWrite(pingPin, LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin, LOW);
    pinMode(pingPin, INPUT);
    duration = pulseIn(pingPin, HIGH);
    return duration / 29 / 2;
}

long int acquisitionMaxSonar(void){
   //variables needed to store values
    long int anVolt, cm;
    int sum=0;//Create sum variable so it can be averaged
    int avgrange=60;//Quantity of values to average (sample size)

  for(int i = 0; i < avgrange ; i++)
  {
    //Used to read in the analog voltage output that is being sent by the MaxSonar device.
    //Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in
    //Arduino analog pin goes from 0 to 1024, so the value has to be divided by 2 to get the actual inches
    anVolt = analogRead(anPin)/2;
    sum += anVolt;
    delay(10);
  }  
  cm = 254* sum/avgrange/100; // 254/100 = 2.54
  }  



void loop()
{
  
   long int valeurPing;
   long int valeurSonar;
   .......
    // on fait l'acquisition des senseurs
   valeurPing = acquisitionPing();
   valeurSonar = acquisitionMaxSonar();

  // on traite les informations recueillies
  // par exemple
  if (valeurSonar>30 and valeurPing>30 ) 
{
digitalWrite(rouge,HIGH);
delay(500);
digitalWrite(rouge,LOW);
delay(500);  
digitalWrite(vert,HIGH);
delay(500);
digitalWrite(vert,LOW);
delay(500); 
digitalWrite(bleu,HIGH);
delay(500);
digitalWrite(bleu,LOW);
delay(500);
  
analogWrite(moteur,170);
delay(500);


}

if (valeurPing < 30 and valeurSonar <30 )
{
    analogWrite(moteur,0);
  delay(500);
  digitalWrite(rouge,HIGH);
  delay(500); 
 }
   
  if(valeurSonar>30 and valeurPing<30)
  
    { 
     analogWrite(moteur, 90);
  delay(500);
  
        for(pos = 0; pos < 180; pos += 1)  
  {                                   
    myservo.write(pos);            

    
   } 
 digitalWrite(vert,HIGH);
 delay(500);
 digitalWrite(vert,LOW);
delay(500); }
  
  if(valeurSonar<30 and valeurPing>30)
{  
  analogWrite(moteur, 90);
  delay(500);
  
   for(pos = 180; pos>=1; pos-=1)      
  {                                
   myservo.write(pos);               
                      
  } 
  digitalWrite(bleu,HIGH);
  delay(500);
  digitalWrite(bleu,LOW);
  delay(500); 
   } 

}

Maintenant, il serait fonctionnel?