bool S0,S1,S2,S3,S4; // Boolean mantiqy toifa
void Read() // o`qish funksiyasi
{
S0=digitalRead(A0); //analog signal qabul qilsh porti
S1=digitalRead(A1); //analog signal qabul qilsh porti
S2=digitalRead(A2); //analog signal qabul qilsh porti
S3=digitalRead(6); //analog signal qabul qilsh porti
S4=digitalRead(9); //analog signal qabul qilsh porti
}
// 5 ta sensor pinlari uchun
void loop() {
if(serial.available())
{
char a=serial.read();
Serial.write(a);
if(a=='1')
{
digitalWrite(b_pin,1);
digitalWrite(a_pin,1);
}
else if(a=='0')
{
digitalWrite(b_pin,0);
digitalWrite(a_pin,0);
}
}
if(Serial.available())
{
serial.write(Serial.read());
}
//---------------------------------------------------
start_time=micros();
int val = analogRead(A3);
float volt = (val / 877.0) * 12.0;
if(!S0 && !S1 && S2 && !S3 && !S4)
{
err=0; // markaziy sensor uchun
}
else if(!S0 && !S1 && !S2 && S3 && !S4)
{
err=1; o`ng tarafdagi 1- sensor
}
else if(!S0 && !S1 && !S2 && !S3 && S4)
{
err=2; ; o`ng tarafdagi 2- sensor
}
else if(!S0 && S1 && !S2 && !S3 && !S4)
{
err=-1; chap tarafdagi 2- sensor
Do'stlaringiz bilan baham: |