hello,
I'm new with arduino and I have to program a robot folower of line with only one captor. I program in a arduino uno. The robot is the rover five. The captor give 1 for a white line and 0 for a black line.
I can't test it yet and I want to no if it's can work with this program.
sorry for my english.
PS: "suiveurligne" is for the line folower
It's normal that the fonction capteur() is not done already already, it's will be a check action with PIR captor an servo to move it.
I put the code under because I don't know how to put it in a window
int E1 = 5;
int M1 = 4;
int E2 = 6;
int M2 = 7;
boolean sl = 2;
long temps;
long controlstop;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(sl, INPUT);
}
void avancer()
{ digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 255); //PWM Speed Control
analogWrite(E2, 255); //PWM Speed Control
}
void reculer()
{ digitalWrite(M1,LOW);
digitalWrite(M2, LOW);
analogWrite(E1, 255); //PWM Speed Control
analogWrite(E2, 255); //PWM Speed Control
}
void tdroit()
{
digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 0); //PWM Speed Control
analogWrite(E2, 255); //PWM Speed Control
}
void tgauche()
{
digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 255); //PWM Speed Control
analogWrite(E2, 0); //PWM Speed Control
}
void rgauche()
{ digitalWrite(M1,LOW);
digitalWrite(M2, LOW);
analogWrite(E1, 255); //PWM Speed Control
analogWrite(E2, 0); //PWM Speed Control
}
void rdroit()
{ digitalWrite(M1,LOW);
digitalWrite(M2, LOW);
analogWrite(E1, 0); //PWM Speed Control
analogWrite(E2, 255); //PWM Speed Control
}
void arret()
{
digitalWrite(M1,LOW);
digitalWrite(M2, LOW);
analogWrite(E1, 0); //PWM Speed Control
analogWrite(E2, 0); //PWM Speed Control
}
void capteur()
{
}
void loop() {
controlstop=millis();
while(digitalRead(sl) == 0)
{
avancer();
if (millis()-controlstop>=10000)
{
capteur();
controlstop = millis();
}
}
while(digitalRead(sl) == 1)
{
temps = millis();
while(digitalRead(sl)==1)
if(millis()-temps<1000)
{
tgauche();
}
if(millis()-temps>=1000 &&(millis()-temps<2000))
{
rgauche();
}
if(millis()-temps>=2000 &&(millis()-temps<3000))
{
tdroit();
}
if(millis()-temps>=3000 &&(millis()-temps<4000))
{
rdroit();
}
if(millis()-temps>=4000 &&(millis()-temps<5000))
{
reculer();
}
if(millis()-temps>=5000 &&(millis()-temps<6000))
{
tgauche();
}
if(millis()-temps>=6000 &&(millis()-temps<7000))
{
rgauche();
}
if(millis()-temps>=7000 &&(millis()-temps<8000))
{
tdroit();
}
if(millis()-temps>=8000 &&(millis()-temps<9000))
{
rdroit();
}
if(millis()-temps>=9000)
{
while(1){}
}
}
}
code_suiveurligne_minicop.ino (2.51 KB)