Servo myservo; #define echopin 2


Download 31 Kb.
Sana31.03.2023
Hajmi31 Kb.
#1314328
Bog'liq
smart park


#include
Servo myservo;

#define echopin 2


#define trigpin 3
#define led 13

int joriy_masofa = 10;


long chastota;
long oraliq_masofa;

void setup(){


Serial.begin(9600);


myservo.attach(4);
myservo.write(0);

pinMode (trigpin, OUTPUT);


pinMode (echopin, INPUT);
pinMode(led,OUTPUT);
delay(1000);
}

void loop(){


ultra_read();


Serial.print("oraliq_masofa=");
Serial.println(oraliq_masofa);

if(oraliq_masofa
myservo.write(120);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
delay(500);
}

if(oraliq_masofa>joriy_masofa){


myservo.write(0);}
delay(100);
}
void ultra_read(){
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
chastota = pulseIn (echopin, HIGH);
oraliq_masofa= chastota/29/2;
}
Download 31 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling