(code Arduino) |
(mef) |
||
Ligne 13 : | Ligne 13 : | ||
void setup() { | void setup() { | ||
− | + | Serial.begin (9600); | |
− | + | pinMode(trigPin, OUTPUT); | |
− | + | pinMode(echoPin, INPUT); | |
− | + | pinMode(trigPin2, OUTPUT); | |
− | + | pinMode(echoPin2, INPUT); | |
− | + | pinMode(ledPin, OUTPUT); | |
− | + | pinMode(ledPin2, OUTPUT); | |
} | } | ||
Ligne 31 : | Ligne 31 : | ||
void loop() { | 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 { | else { | ||
− | + | digitalWrite (ledPin2, LOW); | |
− | + | } | |
− | + | } |
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 :
Vous avez entré un nom de page invalide, avec un ou plusieurs caractères suivants :
< > @ ~ : * € £ ` + = / \ | [ ] { } ; ? #