-1
Hello, I am beginner in the programming study with Arduino, and my teacher asked for the following exercise:
"Using the line follower code implemented in previous lessons, the student must implement a sensor to the right of the robot that will count to 6 when this value is reached the same must stop."
The code he refers to, was made by me and this is it:
int sensorladoesq;
int sensorladodir;
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT); //Este é o motor direito
pinMode(12, OUTPUT); //Este é o motor esquerdo
}
void loop()
{
sensorladoesq = analogRead(A1); //Lê a porta analógica do motor esquerdo
sensorladodir = analogRead(A2); //Lê a porta analógica do motor direito
if ((sensorladoesq < 225) and (sensorladodir < 225)){
Serial.println("Andando pra frente");
digitalWrite(12, HIGH);
digitalWrite(8, HIGH);
}
if (sensorladodir > 225){
Serial.println("Robo virou pra esquerda");
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
}
if (sensorladoesq > 225){
Serial.println("Robo virou pra direita");
digitalWrite(12, HIGH);
digitalWrite(8, LOW);
}
}
I would like help in how to implement this counter, since my teacher has given us no other explanation about.
Thanks in advance.