const int trigPin = 3; const int echoPin = 2; const int trigPin2 = 5; const int echoPin2 = 4; float temps; float temps2; int distance; int distance2; bool ctrue = false; bool c2true = false; int entree = 0; bool fixCheck = false; bool fixCheck2 = false; int fixSomme = 0; int fixSomme2 = 0; int personnesPresentes = 0; void setup() { //Initialization senseurs pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(trigPin2, OUTPUT); pinMode(echoPin2, INPUT); Serial.begin(9600); } void loop() { Distance(); Distance2(); CIsTrue(); CTwoIsTrue(); Fix(); Fix2(); PersonnesPresentes(); Print(); } void CIsTrue() { if (distance >= 65) ctrue = false; else if (distance < 65) ctrue = true; } void CTwoIsTrue() { if (distance2 >= 65) c2true = false; else if (distance2 < 65) c2true = true; } void Fix() { if (entree == 1) { fixSomme++; } else if (entree == 0) { fixSomme = 0; } if (fixSomme == 7) { entree = 0; fixSomme = 0; } } void Fix2() { if (entree == -1) { fixSomme2++; } else if (entree == 0) { fixSomme2 = 0; } if (fixSomme2 == 7) { entree = 0; fixSomme2 = 0; } } void PersonnesPresentes() { if (entree == 0 && ctrue && !c2true) entree = 1; else if (entree == 0 && !ctrue && c2true) entree = -1; if (!ctrue && !c2true && entree != 0) entree = 0; if (entree == 1 && c2true) { personnesPresentes += 1; delay(300); ctrue = false; c2true = false; fixCheck = false; fixCheck2 = false; entree = 0; } else if (entree == -1 && ctrue) { personnesPresentes -= 1; delay(300); ctrue = false; c2true = false; fixCheck = false; fixCheck2 = false; entree = 0; } if (personnesPresentes < 0) personnesPresentes = 0; } int Distance() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); temps = pulseIn(echoPin, HIGH); distance = temps * 0.0347 / 2; return (distance); } int Distance2() { digitalWrite(trigPin2, LOW); delayMicroseconds(2); digitalWrite(trigPin2, HIGH); delayMicroseconds(10); digitalWrite(trigPin2, LOW); temps2 = pulseIn(echoPin2, HIGH); distance2 = temps2 * 0.0347 / 2; return (distance2); } void Print() { Serial.print(distance); Serial.print(" "); Serial.print(distance2); Serial.print(" "); Serial.print(entree); Serial.print(" "); Serial.println(personnesPresentes); }