long tempo=0; const float c=0.017;
void setup() { for(int i=5; i<=7; i++) pinMode(i, OUTPUT); pinMode(13, OUTPUT); //trig pinMode(12, INPUT); //echo Serial.begin(9600); }
void loop() { digitalWrite(13, LOW); digitalWrite(13, HIGH); delayMicroseconds(10); digitalWrite(13, LOW); tempo=pulseIn(12, HIGH); distanza=tempo*c; Serial.print(distanza); Serial.print(” “); Serial.println(tempo); if(distanza<40){ /*digitalWrite(7 ,LOW); digitalWrite(6, LOW); digitalWrite(5, LOW);*/ }
|
else if(distanza>=40 && distanza<100){
digitalWrite(7, HIGH); //digitalWrite(6, LOW); //digitalWrite(5, LOW); } else if(distanza>=100 && distanza<200){ digitalWrite(7, HIGH); digitalWrite(6, HIGH); digitalWrite(5, LOW); } else if(distanza>=200 && distanza<300){ digitalWrite(7, HIGH); digitalWrite(6, HIGH); digitalWrite(5, HIGH); } delay(1000); }
|