I am using Atmega16A and L293D motor driver in my Line Follower. I am using code for following white lines only but now I want it to follow black line.
I first thought they are linked by color I tried changing the color codes, but no result achieved in changing the line color to follow. Here is the code:
#include <avr/io.h>
#include "util/delay.h"
#define s1 ((PINA)&(0x01))
#define s2 ((PINA)&(0x02))
#define ms ((PINA)&(0b00000100))
void forward()
{
PORTD=0b00001001;
}
void left()
{
PORTD=0b00000001;
}
void right()
{
PORTD=0b00001000;
}
void follow()
{
if((ms!=0)&&(s1==0)&&(s2==0))
{
forward();
} else if (s1!=0)
{
left();
}
else if (s2!=0)
{
right();
}
//
// else if((ms==0)&&(s1==0)&&(s2==0))
// {
// right();
// // _delay_ms(150);
//
// }
else if((ms!=0)&&(s1!=0)&&(s2==0))
{
forward();
}
else if((ms!=0)&&(s1==0)&&(s2!=0))
{
forward();
}
else if((ms!=0)&&(s1!=0)&&(s2!=0))
{
forward();
}
else if (ms==0)
{
if (s1!=0)
{
while(ms==0)
{
left();
}
}
else if (s2!=0)
{
while(ms==0)
{
right();
}
}
}
else
{
forward();
}
}
int main(void)
{
DDRA = 0b00000000;
PORTA=0xFF;
DDRD = 0b11111111;
while(1)
{
follow();
}
}