Created
December 16, 2019 04:05
-
-
Save dsvakola/37e0dcc3a5d416480b00e315d069e244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This project is written by Ved Soman | |
Program of Black Line Following Robot | |
using ATMega8 microntroller robotic kit | |
====== For further details about our robotics training | |
====== visit our website at: www.vsa.edu.in | |
*/ | |
#define F_CPU 12000000UL | |
#include <avr/io.h> | |
#include <util/delay.h> | |
int main() | |
{ | |
DDRB=0b00011110; | |
DDRC=0b0000000; | |
DDRD=0b00010000; // output pin for buzzer | |
int s; | |
// user defined functions | |
void Forward() | |
{ | |
PORTB=0b00010010; | |
} | |
void Backward() | |
{ | |
PORTB=0b00001100; | |
} | |
void Stop() | |
{ | |
PORTB=0b0000000; | |
} | |
void SoftLeft() | |
{ | |
PORTB=0b00000010; | |
} | |
void SoftRight() | |
{ | |
PORTB=0b00010000; | |
} | |
void PowerRight() | |
{ | |
PORTB=0b00010100; | |
} | |
void PowerLeft() | |
{ | |
PORTB=0b00001010; | |
} | |
while(1) | |
{ | |
s=PINC&0b0001001; | |
if(s==9) // both sensors are on white | |
{ | |
Forward(); | |
} | |
else if (s==8) // LS is on white, RS is on black | |
{ | |
SoftRight(); | |
PORTD=0b00010000; | |
_delay_ms(60); | |
PORTD=0b00000000; | |
} | |
else if(s==1) // LS is on black, RS is on white | |
{ | |
SoftLeft(); | |
PORTD=0b00010000; | |
_delay_ms(60); | |
PORTD=0b00000000; | |
} | |
else // both sensors are on black | |
/* You can see that how effectively he used the 'else' condition here. */ | |
{ | |
Stop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment