Two LEDs are connected to ledPin1 and ledPin2 You need to co

Two LEDs are connected to ledPin1 and ledPin2. You need to control these LEDs as follows: Step-1. Flash the LED on ledPin1 at 1 flash/sec for four seconds. Step-2: Flash the LED on ledPin2 at 2 flashes/sec for four seconds. Continuously repeat Step-1 and Step-2 Write a void loop () to do the above operations.

Solution

void delay_loop(int n) //delay loop for n second
{
int c = 1, d = 1;

for ( c = 1 ; c <= n*32767 ; c++ )
for ( d = 1 ; d <= 32767 ; d++ ) //n second loop
{
}  
}

void LED_ON()
{

PORTC = 0x01 //TURNS LED ON

}

void LED_OFF()
{

PORTC = 0x00 //TURNS LED OFF

}

int main()
{
DDRC = 0xFF; //MAKES PORTC OUTPUT PORT

while(1)
{
for ( c = 1 ; c <= 4*32767 ; c++ ) //this will run for 4 second (STEP 1 CODE)
{
for ( d = 1 ; d <= 32767 ; d++ )   
{   
LED_ON();
delay_loop(0.5);           //Everthing inside this for loop will happen till 4 second
LED_OFF();
delay_loop(0.5);
}
}

for ( c = 1 ; c <= 4*32767 ; c++ ) //this will run for 4 second (STEP 2 CODE)
{
for ( d = 1 ; d <= 32767 ; d++ )   
{
LED_ON();
delay_loop(0.25);            //Everthing inside this for loop will happen till 4 second
LED_OFF();
delay_loop(0.25);
}
}

Note: Please include necessary libraries respective to you microcontroller. This code is for AVR controller.

 Two LEDs are connected to ledPin1 and ledPin2. You need to control these LEDs as follows: Step-1. Flash the LED on ledPin1 at 1 flash/sec for four seconds. Ste

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site