How to produce running effect of LEDs in your robotic kit?

This is the second program in your course of FUNDAMENTALS OF ROBOTICS. To use this program, you must use our robotics kit already supplied to you.

If you do not have this kit, then you can purchase our distance learning programme in robotics or contact us to join our regular batches of robotics.

Now read the following program carefully and work as per the given instructions, to enjoy your first program in robotics.

To use this program directly for your robotic kit, copy it, create new project in AVR Studio and then paste it into the coding area. Then compile it.

/*
	Level II project of Running LEDs 
	Applicable to ATMega8/16/32/128
	Designed by: Vidyasagar Academy, Akola
	Website: www.vsagar.org

	*** CONNECTION DETAILS OF KIT ***
	PB4-PB1 	: output pins of PORTB, connected to 4 LEDs

*/

#define F_CPU 12000000UL // defining the crystal frequency 12MHz 
			// given on your dev. board of ATMega8

#include <avr/io.h> // including the input-output 
		// to define the input output ports and pins
		// this file is inside the AVR folder 					

#include <util/delay.h> // including the delay file
			// this file is inside the 
			// utilities (util) folder

	int main() // starting the main function of program

	{ // main function brace opened

	DDRB=0b00011110; // PB4-PB1 of PORTB are defined as output pins

	while(1) // starting the infinite loop to repeat the action infinitely
	
	{ // while loop brace opened

	PORTB=0b00000010; // 1st LED at PB1 becomes ON

	_delay_ms(300); // it remains ON for 300ms=0.3sec

	PORTB=0b00000100; // 2nd LED at PB2 becomes ON

	_delay_ms(300); // it remains ON for 300ms=0.3sec
	
	PORTB=0b00001000; // 3rd LED at PB3 becomes ON

	_delay_ms(300); // it remains ON for 300ms=0.3sec

	PORTB=0b00010000; // 4th LED at PB4 becomes ON

	_delay_ms(300); // it remains ON for 300ms=0.3sec

/* 
	
	**** IMPORTANT COMMENT ****
	
	After this last step, the program will jump to first step 
	and will repeat infinitely, since it is within while(1) loop
	called as infinite loop.

	YOU CAN CHANGE THE DELAY IN MILLI SECONDS AS REQUIRED.

*/ 

	} // while loop brace closed

	} // main function brace closed

About the author: Admin of Vidyasagar Academy to post all types of educational material required for our students. This material is equally helpful to our online students.

Comments on this entry are closed.