Ето я цялата програма :
#define E1 3
#define E2 11
#define M1 12
#define M2 13
int val;
void M_Control_IO_config(void)// initialization function of motor driver shield IO
{
pinMode(M1,OUTPUT); //
pinMode(M2,OUTPUT); //
pinMode(E1,OUTPUT); //
pinMode(E2,OUTPUT); //
}
void advance(void) // move forward
{
digitalWrite(M1,LOW); // right wheel moves forward
digitalWrite(M2, LOW); // left wheel moves forward
analogWrite(E1,150);
analogWrite(E2, 150);
}
void turnR(void) // turn right
{
digitalWrite(M1,LOW); // left wheel moves forward
digitalWrite(M2,HIGH); // right wheel moves forward
analogWrite(E1,150);
analogWrite(E2, 150);
}
void turnL(void) // turn left
{
digitalWrite(M1,HIGH); // left wheel moves backward
digitalWrite(M2, LOW); // right wheel moves forward
analogWrite(E1,150);
analogWrite(E2, 150);
}
void stopp(void) // stop
{
digitalWrite(M1,LOW);
digitalWrite(M2, LOW);
analogWrite(E1, 0);
analogWrite(E2, 0); // both left and right wheel stop
}
void back(void) // move backward
{
digitalWrite(M1,HIGH); // both left and right wheel move backward
digitalWrite(M2, HIGH);
analogWrite(E1,150);
analogWrite(E2, 150);
}
void sensors(void)
{
}
void setup()
{
Serial.begin(9600);
M_Control_IO_config(); // initialization of motor driver shield IO
stopp();
}
void loop()
{
val=Serial.read();
if(val=='1')advance();
if(val=='2')back();
if(val=='3')turnL();
if(val=='4')turnR();
if(val=='5')stopp();
if(val=='6')*/
Sensor_Scan();
if(IRSL==1&&IRSM==1&&IRSR==1)advance();
else if((IRSL==0&&IRSM==0&&IRSR==1)||(IRSL==0&&IRSM==1&&IRSR==1)||(IRSL==1&&IRSM==0&&IRSR==1))turnL();
else if((IRSL==0&&IRSM==0&&IRSR==0)||(IRSL==1&&IRSM==0&&IRSR==0)||(IRSL==1&&IRSM==1&&IRSR==0))turnR();
}