30.5k views
2 votes
Write a program that will cycle through the different color combinations of the RGB LED. The program will cycle through the RGB color combinations twice. After the second cycle through the RGB colors, the red LED on port 1 pin 0, and the blue LED will alternate flashing ON/OFF.

1 Answer

2 votes

Answer:

#include<stdio.h>

void main()

{

char color;

clrscr();

print ("Enter character (R/G/B ) :");

color= getchar();

switch (color)

{

case 'R':

printf ("Red");

break;

case 'G':

printf ("Green");

break;

case 'B':

printf ("Blue");

break;

}

{

while(1)

{ led_on();

for(int i=0; i< 0*fff; i++);

led_off();

for(int i=0; i< 0*fff; i++);

}

return 0;

}

void loop()

{

char input;

while (LED() >0)

{

input = LED.read();

if(input == '1')

digitalWrire(led, HIGH); //on

if(input == '0')

digitalWrire(led, LOW); //off

}

getch();

}

Step-by-step explanation:

#include<stdio.h>

void main()

{

char color;

clrscr();

print ("Enter character (R/G/B ) :");

color= getchar();

switch (color)

{

case 'R':

printf ("Red");

break;

case 'G':

printf ("Green");

break;

case 'B':

printf ("Blue");

break;

}

{

while(1)

{ led_on();

for(int i=0; i< 0*fff; i++);

led_off();

for(int i=0; i< 0*fff; i++);

}

return 0;

}

void loop()

{

char input;

while (LED() >0)

{

input = LED.read();

if(input == '1')

digitalWrire(led, HIGH); //on

if(input == '0')

digitalWrire(led, LOW); //off

}

getch();

}

The program above is to determine which colour does what in a traffic situation.

It cycle through the different color combinations of the RGB LED. The program will cycle through the RGB color combinations twice. After the second cycle through the RGB colors, the red LED on port 1 pin 0, and the blue LED will alternate flashing ON/OFF.

User Jan Petr
by
4.9k points