Page 249 - MDP2022-3
P. 249

delayMicroseconds(2);


                digitalWrite(TRIG,  HIGH);



                delayMicroseconds(10);


                digitalWrite(TRIG,  LOW);





                duration  =  pulseIn  (ECHO,  HIGH);


                distance  =  duration  *  17  /  1000;




                Serial.print("\nDIstance  :  ");



                Serial.print(distance);


                Serial.println("  Cm");



                if(distance  <=  15  ||  distance  >=  2500){
                    Serial.println("문에  부딛힐  위험이  있습니다!");
                    digitalWrite(LED,  HIGH);
                    tone(BOOZER,  254);
                    delay(100);

                    digitalWrite(LED,LOW);
                    noTone(BOOZER);
                    delay(100);
                }

                else  if(distance  >  15){
                    Serial.println("안전합니다");
                    digitalWrite(LED,LOW);
                    noTone(BOOZER);
                    delay(500);
                }

            }
   244   245   246   247   248   249   250   251   252   253   254