| @@ -28,23 +28,40 @@ void setup() { | |||||
| Serial.println("BTS Ecole Technique EME"); | Serial.println("BTS Ecole Technique EME"); | ||||
| myServo.attach(10); | myServo.attach(10); | ||||
| myServo.write(5); | myServo.write(5); | ||||
| } | } | ||||
| void loop() { | void loop() { | ||||
| digitalWrite(trigPin, LOW); | digitalWrite(trigPin, LOW); | ||||
| delayMicroseconds(2); | delayMicroseconds(2); | ||||
| digitalWrite(trigPin, HIGH); | digitalWrite(trigPin, HIGH); | ||||
| delayMicroseconds(10); | delayMicroseconds(10); | ||||
| digitalWrite(trigPin, LOW); | digitalWrite(trigPin, LOW); | ||||
| duration = pulseIn(echoPin, HIGH); | duration = pulseIn(echoPin, HIGH); | ||||
| distance = duration * 0.034 / 2; | distance = duration * 0.034 / 2; | ||||
| if (distance < 30 && distance > 1) { ouverture(); } | |||||
| if (distance > 30) { Serial.println("-"); fermeture(); } | |||||
| Serial.println(distance); | 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(){ | void ouverture(){ | ||||
| Serial.println("Ouverture du bouchon"); | Serial.println("Ouverture du bouchon"); | ||||
| digitalWrite(13, HIGH); | digitalWrite(13, HIGH); | ||||
| myServo.write(170); | |||||
| delay(1000); | |||||
| delay(3000); | |||||
| Serial.println("Fermeture du bouchon"); | Serial.println("Fermeture du bouchon"); | ||||
| digitalWrite(13, LOW); | digitalWrite(13, LOW); | ||||
| delay(2000); | delay(2000); | ||||
| myServo.write(5); | |||||
| } | } | ||||
| void fermeture(){} | |||||