int rm1=2;  // IN4
int rm2=3;  // IN3
int lm1=7;   //IN1
int lm2=4;  //IN2
int skorl=6; //EN2
int skorr=5;  //EN1
int spl=120;
int spr=120;
int DL=13;    // черная линия дает - 1, а белая - 0
int DC=9;
int DR=12;



void setup() {
pinMode (lm1, OUTPUT); 
pinMode (lm2, OUTPUT); 
pinMode (rm1, OUTPUT); 
pinMode (rm2, OUTPUT);
pinMode (skorl, OUTPUT); 
pinMode (skorr, OUTPUT);  
pinMode (DL, INPUT);
pinMode (DC, INPUT);
pinMode (DR, INPUT);
Serial.begin (9600);
delay (5000);
}

void loop() {
vpered(); delay (20);
int  R=digitalRead(DR);
int  C=digitalRead(DC);
int  L=digitalRead(DL);
while (R==1 && C==0 && L==0) {
napravo(); delay(10);
R=digitalRead(DR);
C=digitalRead(DC);
L=digitalRead(DL);}  ;
while (R==0 && C==1 && L==0) {
vpered();delay(10);
R=digitalRead(DR);
C=digitalRead(DC);
L=digitalRead(DL);} ;
while (R==0 && C==0 && L==1) {
nalevo();delay(10);
R=digitalRead(DR);
C=digitalRead(DC);
L=digitalRead(DL);}  ;
}
void ostanovka () {
digitalWrite (lm1,0);
digitalWrite (lm2,0);
digitalWrite (rm1,0);
digitalWrite (rm2,0);
analogWrite (skorl, spl);
analogWrite (skorr, spr);
}
void vpered () {
digitalWrite (lm1,HIGH);
digitalWrite (lm2,LOW);
digitalWrite (rm1,HIGH);
digitalWrite (rm2,LOW);
analogWrite (skorl, spl);
analogWrite (skorr, spr);
}

void nazad () {
digitalWrite (lm1,0);
digitalWrite (lm2,1);
digitalWrite (rm1,0);
digitalWrite (rm2,1);
analogWrite (skorl, spl);
analogWrite (skorr, spr);
}

void napravo () {
digitalWrite (lm1,1);
digitalWrite (lm2,0);
digitalWrite (rm1,0);
digitalWrite (rm2,1);
analogWrite (skorl, spl);
analogWrite (skorr, spr);
}


void nalevo () {
digitalWrite (lm1,0);
digitalWrite (lm2,1);
digitalWrite (rm1,1);
digitalWrite (rm2,0);
analogWrite (skorl, spl);
analogWrite (skorr, spr);
}





