i have a line following robot programme.
#include<avr/io.h>
#define left_sensor PD0 // Left sensor
#define middle_sensor PD1 // Middle sensor
#define right_sensor PD2 // Right sensor
#define sensor_port PORTD
#define sensor_pin PIND
#define sensor_ddr DDRD
#define Motor_L1 PB2 //Left positive motor
#define Motor_L2 PB3 //Left negetive motor
#define Motor_R1 PB1 //Right positive motor
#define Motor_R2 PB0 //Right negetive motor
int forward()
{
PORTB&=~((Motor_L2)|(Motor_R2)); //turn Off PB3,PB0
PORTB|=(Motor_L1)|(Motor_R1); //turn On PB2 and PB1
return 0;
}
int reverse()
{
PORTB&=~((Motor_L1)|(Motor_R1)); //turn Off PB2,PB1
PORTB|=(Motor_L2)|(Motor_R2); //turn On PB3 ,PB0
return 0;
}
int for_left()
{
PORTB&=~((Motor_L2)|(Motor_R2)|(Motor_R1)); //turn Off PB3 , PB0 and PB1
PORTB|=(Motor_L1); //turn On PB2
return 0;
}
int for_right()
{
PORTB&=~((Motor_L1)|(Motor_R1)|(Motor_L2)); //turn Off PB2 , PB1,PB3
PORTB|=(Motor_R1); //turn On PB0
return 0;
}
int main()
{
// ***** Setup Ports and sensors
DDRB|=(PB0)|(PB1)|(PB2)|(PB3); //motor
PORTD|=(PD1)|(PD2)|(PD0); //front sensors
// ***** Insert code here to move forward
while(1)
{
// Where is the black line?
// if(sensor_pin&((left_sensor)|(middle_sensor)|(right_sensor)))
// if(sensor_pin&((PD0)|(PD1)|(PD2)))
// {
// forward();
// }
if(sensor_pin&((middle_sensor)))
{
forward();
}
else if(sensor_pin&((left_sensor)))
{
for_left();
}
else if(sensor_pin&((right_sensor)))
{
for_right();
}
else
{
forward();
}
}
}
can someone tell me what does [ PORTB&=~((Motor_L2)|(Motor_R2)|(Motor_R1)); //turn Off PB3 , PB0 and PB1
PORTB|=(Motor_L1); //turn On PB2] stands for and how it works , how operators work here & [ DDRB|=(PB0)|(PB1)|(PB2)|(PB3); //motor
PORTD|=(PD1)|(PD2)|(PD0); //front sensors ] how ports are initialize here.