Fichier:Code Arduino BabyFoot

int ledPin = 10;

int ledPin2 = 5;

int trigPin = 13;

int echoPin = 12;

int trigPin2 = 7;

int echoPin2 = 6;

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(trigPin2, OUTPUT);

pinMode(echoPin2, INPUT);

pinMode(ledPin, OUTPUT);

pinMode(ledPin2, OUTPUT);

}

void loop() {

int duration, distance;

digitalWrite (trigPin, HIGH);

delayMicroseconds (10);

digitalWrite (trigPin, LOW);

duration = pulseIn (echoPin, HIGH);

distance = (duration/2) / 29.1;

Serial.print(distance);

Serial.print("cm");

Serial.println();

if (distance < 30) {// Change the number for long or short distances.

digitalWrite (ledPin, HIGH);

} else {

digitalWrite (ledPin, LOW);

}

int duration2, distance2;

digitalWrite (trigPin2, HIGH);

delayMicroseconds (10);

digitalWrite (trigPin2, LOW);

duration = pulseIn (echoPin2, HIGH);

distance2 = (duration/2) / 29.1;

Serial.print(distance2);

Serial.print("cm");

Serial.println();

if (distance2 < 20) {// Change the number for long or short distances.

digitalWrite (ledPin2, HIGH);

}

else {

digitalWrite (ledPin2, LOW);

}

}

Les 2 pages suivantes utilisent ce fichier :