#define F_CPU 1000000UL // 1 MHz
#include <inttypes.h>
#include <avr/io.h>
int main() // The main function
{
DDRD = 0b00000000;// Set all the pin of portD as input
DDRB = 0b11111111; // Set all the pin of portB as output
while(PIND==0b00001111)
{
PORTB = 0b00000101; // both motor rotate Clock Wise
}
while (PIND==0b00001101)
{
PORTB = 0b00000100; // left motor stop and right motor rotate CW
}
while(PIND==0b00001100)
{
PORTB = 0b00000110; // left motor CW and right motor counter clock wise (CCW)
}
while (PIND==0b00001011)
{
PORTB = 0b00000001; // left motor CW and right motor stop
}
while (PIND==0b00000011)
{
PORTB = 0b00001001; // left motor CW and right motor CCW
}
}