Je pensais que la distance était gérée par les ultrasons !? avec if cm < 15 cm dans
les fonctions aléatoires et ultrasons
dans la fonction bordure j'utiliserai cela
if( (buttonState==HIGH) && (cm<=15) ) ... // contact ET ultrason, le bateau met en route le moteur coté bord pour s'en écarter un peu
Puis
if( (buttonState==HIGH) && !(cm<=15) ) ... // contact sans ultrason le bateau met en route le moteur coté inverse du bord pour se plaquer contre ce bord
mais je mets cm< 5cm
C'est possible de passer de 15 à 5 cm de détection dans cette fonction ?
PS : erreur dans la console
exit status 1
'bordure' was not declared in this scope
PS bis : mon code était presque bon 
/*
This code corresponds to a floating boat with rudimentary sensing capabilities -
step by step instructions and images are at levinegabriella.com/teaching
It includes an parallax ultrasonic rangefinder : see data sheet
http://www.arduino.cc/en/Tutorial/Ping
which allows the boat to turn away from obstacles ahead.
It also includes two reed switches so if it hits barriers from the side, it
turns around away from the wall
created 2011 by gabriella levine
*/
/*
En C/C++ un ET logique se note &&. Un OU logique se note ||. La négation se note !. Donc cela ressemblera à :
if( (buttonState==HIGH) && (cm<=15) ) ... // contact ET ultrason
if( (buttonState==HIGH) && !(cm<=15) ) ... // contact sans ultrason
Remarque : pour le dernier cas on peut écrire if( (buttonState==HIGHT) && (cm>15) ) ... // contact sans ultrason
*/
// constants
// set pin numbers:
const int pingPin = 7;
const int DetecteurPin1 = 2; // the number of the pushbutton pin Le numéro de l'épingle à commande automatique(presse-bouton)
const int DetecteurPin2 = 4;
const int moteur1 = 3; // the number of the motor pin le (numéro l'épingle du moteur
const int moteur2 = 11;
//
//**************************************************************************************************
const int pompe = 10; // declaration pompe au pin 10 ********************************************
//**************************************************************************************************
// variables
int BtnContact = 0; // variable for reading the pushbutton status variable pour lire le statut du 1er bouton de contact
int BtnContact1 = 0; //
// Variable globale pour faire le décompte du temps
unsigned long startMillis; // à 0 par défaut
long cm = 0;
//variable pour lire le statut du 2 ieme bouton de contact
void setup() {
//begin serial
Serial.begin(9600);
// initialise les pin moteurs à OUTPUT, soit éteint
pinMode(moteur1, OUTPUT);
pinMode(moteur2, OUTPUT);
// initialise les boutons contact pins à INPUT, soit actif:
pinMode(DetecteurPin1, INPUT);
pinMode(DetecteurPin2, INPUT);
//**************************************************************************************************
// initialize the pump pins as output: au démarrage la pompe ne marche pas ***********************
pinMode(pompe, OUTPUT);
// *************************************************************************************************
//
}
void loop() {
// dès le départ le bateau bouge aléatoirement
long tempsEcoule = millis() - startMillis;
if (tempsEcoule < 10000) aleatoire();
else if (tempsEcoule < 20000) bordure();
else startMillis = millis();
ultrasons ();
delay (100);
}
//******
//******
//******
void button() {
// vérifie si les boutoncontact sont actifs(HIGH), si oui le moteur passe à actif(HIGH) ou éteint(LOW) selon le programme
if (BtnContact1 == HIGH) {
// turn LED on:
digitalWrite(moteur1, LOW);
//
//**************************************************************************************************
// si le bouton touche le bord la pompe fonctionne *************************************************
digitalWrite(pompe, HIGH);
//**************************************************************************************************
}
else {
// turn LED off:
digitalWrite(moteur1, HIGH);
//
//**************************************************************************************************
// sinon pas de contact la pompe stoppe ************************************************************
digitalWrite(pompe, LOW);
//**************************************************************************************************
}
if (BtnContact == HIGH) {
// turn LED on:
digitalWrite(moteur2, LOW);
//
//**************************************************************************************************
// si le bouton touche le bord la pompe fonctionne *************************************************
digitalWrite(pompe, HIGH);
//**************************************************************************************************
}
else {
// turn LED off:
digitalWrite(moteur2, HIGH);
//
//**************************************************************************************************
// sinon pas de contact la pompe stoppe ************************************************************
digitalWrite(pompe, LOW);
//**************************************************************************************************
}
}
void ultrasons() {
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse.
//Le PING))) est déclenché par un contact de 2 ou plusieurs micro-secondes.
//Donnez une impulsion ETEINT courte à l'avance pour assurer une impulsion MARCHE propre
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
/*
le même pin est utilisé pour lire le signal du PING))) : impulsion
dont la durée est le temps (en micro-secondes) de l'émission
du Ping à la réception de son écho sur un objet.
*/
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
cm = microsecondsToCentimeters(duration);
}
void aleatoire() {
if (cm <= 15) {
//digitalWrite(moteur, LOW);
digitalWrite(moteur2, LOW);
//
//**************************************************************************************************
// à moins de 15 cm la pompe fonctionne ************************************************************
digitalWrite(pompe, HIGH);
//**************************************************************************************************
}
else {
//digitalWrite(moteur, HIGH);
digitalWrite(moteur2, HIGH);
//
//**************************************************************************************************
// sinon à plus de 15 cm la pompe stoppe ***********************************************************
digitalWrite(pompe, LOW);
//**************************************************************************************************
button();
}
}
void bordures() {
/*
En C/C++ un ET logique se note &&. Un OU logique se note ||. La négation se note !. Donc cela ressemblera à :
if( (buttonState==HIGH) && (cm<=5) ) ... // contact ET ultrason
if( (buttonState==HIGH) && !(cm<=5) ) ... // contact sans ultrason
Remarque : pour le dernier cas on peut écrire if( (buttonState==HIGHT) && (cm>5) ) ... // contact sans ultrason
*/
}
//******
//******
//******
long microsecondsToCentimeters(long microseconds)
{
/*
La vitesse du son est 340 m/s ou 29 micro-secondes par centimètre.
Le tintement voyage d'et en arrière, ainsi trouver la distance de le
L'objet nous prenons la moitié de la distance a voyagé.
*/
return microseconds / 29 / 2;
}