#define trig 11
#define echo 12
const int m1a=5;
const int m1b=6;
const int m2a=9;
const int m2b=10;
void setup() {
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
long duration, distance;
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = (duration/2) / 29.1;
if (distance < 10) {
analogWrite(m1a=105);
analogWrite(m1b=0);
analogWrite(m2a=0);
analogWrite(m2b=105);
}
else {
analogWrite(m1a=110);
analogWrite(m1b=0);
analogWrite(m2a=110);
analogWrite(m2b=0);
}
}