70-2WD araba engelden kaçan

2WD araba engelden kaçan
					

#define trigPin 13
#define echoPin 12

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin (9600);
       
}

void dur()
    {
        analogWrite(5,0);
        analogWrite(6,0);
        analogWrite(9,0);
        analogWrite(10,0);
    }

void ileri()
    {
        analogWrite(5,255);
        analogWrite(6,0);
        analogWrite(9,0);
        analogWrite(10,255);
    }

void geri()
    {
        analogWrite(5,0);
        analogWrite(6,255);
        analogWrite(9,255);
        analogWrite(10,0);
    }

void sag()
    {
        analogWrite(5,0);
        analogWrite(6,0);
        analogWrite(9,0);
        analogWrite(10,255);
    }

void sol()
    {
        analogWrite(5,255);
        analogWrite(6,0);
        analogWrite(9,0);
        analogWrite(10,0);
    }

void loop() {
  int sure, mesafe;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  sure = pulseIn(echoPin, HIGH);
  mesafe = sure/58; 
  
    Serial.print(mesafe);
    Serial.println(" cm");

  if (!(mesafe < 10))
    {
        ileri();
    }
  else
  {
    geri();
    delay(1000);
    sol();
    delay(1000);
  }
}