Page 83 - Proyecto
P. 83

void loop()
                                    {  digitalWrite(trig, HIGH);
                                      delay(1);
                                      digitalWrite(trig, LOW);
                                      t= pulseIn(echo, HIGH);
                                      d= t/58.2;
                                      delay(1);

                                      if (d >150)
                                    {   digitalWrite (ld1, LOW);
                                        digitalWrite (ld2, LOW);
                                        digitalWrite (ld3, LOW);
                                        Serial.println("cm");
                                        Serial.print(d);      }
                                      if (d <150)
                                    {   digitalWrite (ld1, HIGH);
                                        delay(1);
                                        digitalWrite (ld2, LOW);
                                        digitalWrite (ld3, LOW);
                                        Serial.println("cm");
                                        Serial.print(d);    }
                                       if (d<100)
                                    {    digitalWrite (ld1, HIGH);
                                         digitalWrite (ld2, HIGH);
                                         delay(1);
                                        digitalWrite (ld3, LOW);
                                       Serial.println("cm");
                                       Serial.print(d);   }
                                        if (d<50)
                                     {    digitalWrite (ld1, HIGH);
                                          digitalWrite (ld2, HIGH);
                                          digitalWrite (ld3, HIGH);
                                          delay(500);
                                         Serial.println("cm");
                                         Serial.print(d);       }
                                       dato=digitalRead(pir);
                                      if(dato==HIGH && d<150)
                                       {   digitalWrite(ldf, HIGH);  }
                                       else
                                       digitalWrite(ldf, LOW);
                                       delay(10);
                                    }










                                                           78
   78   79   80   81   82   83   84   85   86   87   88