Want to take admission? Contact us! • Find us on Google Map

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

11-12th Bifocal Electronics Notes

Vidyasagar Academy, Akola is a trusted name in the field of education. If you liked our free downloads, please write Google Review about us or follow us on Google+.

This is the third 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 using "FOR LOOP"
	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

	int i=0; // variable to store the particular value

	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

		for (i=0; i<4; i++)	// loop to count value of ‘i’
		{
		PORTB=(1<<i);		// left shift operator 
		_delay_ms (500);	// delay of 1 second 
		}

	} // while loop brace closed

	} // main function brace closed

/* 
	=== HOW TO USE AND RUN THIS PROGRAM IN YOUR KIT? ===
	1) First read the program carefully. Understand the steps as taught to you.
	2) Connect your kit to USB port.
	3) Burn the 'hex' file into your kit.
	4) Now connect battery and switch on the kit.
	6) The 4 LEDs will glow one-by-one in a particular direction.
	7) Is it working? Nice! You did it.
	8) Now don't forget to give your feedback.
	
	**** IMPORTANT NOTE ****
	
	The 'for loop' will start from '0'. At this condition, PB1=1 only.
	When i=1, PB2=1 only.
	When i=2, PB3=1 only.
	When i=3, PB2=4 only.
	In this way, using 'for loop' you can get the same effect of 
	running LEDs which we saw in previous project of running LEDs

*/ 

Comments on this entry are closed.