|
|
|
@@ -28,23 +28,40 @@ void setup() { |
|
|
|
Serial.println("BTS Ecole Technique EME"); |
|
|
|
myServo.attach(10); |
|
|
|
myServo.write(5); |
|
|
|
|
|
|
|
} |
|
|
|
void loop() { |
|
|
|
|
|
|
|
|
|
|
|
digitalWrite(trigPin, LOW); |
|
|
|
delayMicroseconds(2); |
|
|
|
|
|
|
|
digitalWrite(trigPin, HIGH); |
|
|
|
delayMicroseconds(10); |
|
|
|
digitalWrite(trigPin, LOW); |
|
|
|
|
|
|
|
duration = pulseIn(echoPin, HIGH); |
|
|
|
distance = duration * 0.034 / 2; |
|
|
|
|
|
|
|
|
|
|
|
if (distance < 30 && distance > 1) { ouverture(); } |
|
|
|
if (distance > 30) { Serial.println("-"); fermeture(); } |
|
|
|
Serial.println(distance); |
|
|
|
|
|
|
|
myServo.write(5); |
|
|
|
if (distance < 30 && distance > 1) { |
|
|
|
|
|
|
|
delay(500); |
|
|
|
|
|
|
|
Serial.println("1ere verification validée, on passe à la suivante"); |
|
|
|
digitalWrite(trigPin, LOW); |
|
|
|
delayMicroseconds(2); |
|
|
|
digitalWrite(trigPin, HIGH); |
|
|
|
delayMicroseconds(10); |
|
|
|
digitalWrite(trigPin, LOW); |
|
|
|
duration = pulseIn(echoPin, HIGH); |
|
|
|
distance = duration * 0.034 / 2; |
|
|
|
|
|
|
|
if (distance < 30 && distance > 1) {myServo.write(170); ouverture(); } |
|
|
|
} |
|
|
|
if (distance > 30) { myServo.write(170);} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@@ -52,14 +69,9 @@ void loop() { |
|
|
|
void ouverture(){ |
|
|
|
Serial.println("Ouverture du bouchon"); |
|
|
|
digitalWrite(13, HIGH); |
|
|
|
myServo.write(170); |
|
|
|
delay(1000); |
|
|
|
delay(3000); |
|
|
|
Serial.println("Fermeture du bouchon"); |
|
|
|
digitalWrite(13, LOW); |
|
|
|
|
|
|
|
delay(2000); |
|
|
|
myServo.write(5); |
|
|
|
} |
|
|
|
|
|
|
|
void fermeture(){} |
|
|
|
|
|
|
|
|