Documente Academic
Documente Profesional
Documente Cultură
#define lMotorCathode 7
#define rMotorAnode 13
#define rMotorCathode 12
#define vhighSpeed 255
#define highSpeed 255
#define lowSpeed 50
#define vlowSpeed 25
int irRight = 0;
int irRiiight = 0;
int irLeft = 0;
int irLeeeft = 0;
void setup()
{
//Serial.begin(9600);
pinMode(lMotorCathode, OUTPUT);
pinMode(lMotorAnode, OUTPUT);
pinMode(lMotorCathode, OUTPUT);
pinMode(lMotorAnode, OUTPUT);
pinMode(irRightPin, INPUT);
pinMode(irRiiightPin, INPUT);
pinMode(irLeftPin, INPUT);
pinMode(irLeeeftPin, INPUT);
pinMode(rSpeed,OUTPUT);
pinMode(lSpeed,OUTPUT);
digitalWrite(rMotorCathode, LOW);
digitalWrite(rMotorAnode, LOW);
digitalWrite(lMotorCathode, LOW);
digitalWrite(lMotorAnode, LOW);
}
void loop()
{
readSensors();
//Serial.println(irRight);
if (irLeeeft == 0 && irLeft == 1 && irRight == 1 && irRiiight == 0)
{
motorOn();
straight();
}
else if (irLeeeft == 1 && irLeft == 1 && irRight == 1 && irRiiight == 0)
{
motorOn();
leftTurn();
}
else if (irLeeeft == 1 && /*irLeft == 1 &&*/ irRight == 0 && irRiiight == 0)
{
motorOn();
hardLeftTurn();
}
else if (irLeeeft == 0 && irLeft == 1 && irRight == 1 && irRiiight == 1)
{
motorOn();
rightTurn();
}
else if (irLeeeft == 0 && irLeft == 0 /*&& irRight == 1*/ && irRiiight == 1)
{
motorOn();
hardRightTurn();
}
else if (irLeeeft == 1 && irLeft == 1 && irRight == 1 && irRiiight == 1)
{
motorOn();
off();
}
else if (irLeeeft == 0 && irLeft == 0 && irRight == 0 && irRiiight == 0)
{
straight();
delay(100);
off();
}
}
void motorOn()
{
digitalWrite(rMotorCathode, HIGH);
digitalWrite(rMotorAnode, LOW);
digitalWrite(lMotorCathode, HIGH);
digitalWrite(lMotorAnode, LOW);
}
void straight()
{
analogWrite(rSpeed, highSpeed);
analogWrite(lSpeed, highSpeed);
}
void leftTurn()
{
analogWrite(rSpeed, highSpeed);
analogWrite(lSpeed, lowSpeed);
void hardLeftTurn()
{
analogWrite(rSpeed, vhighSpeed);
analogWrite(lSpeed, vlowSpeed);
void rightTurn()
{
analogWrite(rSpeed, lowSpeed);
analogWrite(lSpeed, highSpeed);
}
void hardRightTurn()
{
analogWrite(rSpeed, vlowSpeed);
analogWrite(lSpeed, vhighSpeed);
void off()
{
digitalWrite(rMotorCathode, LOW);
digitalWrite(rMotorAnode, LOW);
digitalWrite(lMotorCathode, LOW);
digitalWrite(lMotorAnode, LOW);
}
void readSensors()
{
irLeft = digitalRead(irLeftPin);
irLeeeft = digitalRead(irLeeeftPin);
irRight = digitalRead(irRightPin);
irRiiight = digitalRead(irRiiightPin);
}