From 92712e7480991caa87b93fd2aca25c529b3b0fa9 Mon Sep 17 00:00:00 2001 From: TheBidouilleur Date: Wed, 7 Oct 2020 14:44:59 +0200 Subject: [PATCH] Suppression de la valeur "0" pour l'ouverture --- main_Serv_Sensor.ino | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main_Serv_Sensor.ino b/main_Serv_Sensor.ino index 441c59d..44e9539 100644 --- a/main_Serv_Sensor.ino +++ b/main_Serv_Sensor.ino @@ -1,5 +1,9 @@ // ---------------------------------------------------------------- // - +// Arduino Ultrasoninc Sensor HC-SR04 +// Re-writed by Arbi Abdul Jabbaar +// Using Arduino IDE 1.8.7 +// Using HC-SR04 Module +// Tested on 17 September 2019 // ---------------------------------------------------------------- // #define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04 @@ -35,19 +39,17 @@ void loop() { digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); - distance = duration * 0.034 / 2; - if (distance < 30 ) { ouverture(); } - if (distance > 30) { Serial.println("-"); } - + if (distance < 30 && distance > 1) { ouverture(); } + if (distance > 30) { Serial.println("-"); fermeture(); } + Serial.println(distance); } void ouverture(){ - Serial.println("Ouverture du bouchon"); digitalWrite(13, HIGH); myServo.write(170); @@ -55,11 +57,9 @@ void ouverture(){ Serial.println("Fermeture du bouchon"); digitalWrite(13, LOW); delay(2000); - myServo.write(5); - - - - + myServo.write(5); } - +void fermeture(){} + + \ No newline at end of file