Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Arduino code . need some help to do RGB LED. Now, write a program to show all po

ID: 2248849 • Letter: A

Question

Arduino code . need some help to do RGB LED.

Now, write a program to show all possible colors the RGB LED can display in a continuing loop. Remember, each color (R, G, B) can vary between 0 and 255. The easiest way to achieve this is with for loops. Here’s the sequence:

//Start will all LEDs off

//Vary red from 0 to 255 - transition to red

for (int i = 0; i <= 255; i++) {
   analogWrite(red, i);
   delay(10);
}

//Vary green from 0 to 255 - transition to yellow

-Add another for loop here for green...

//Vary red from 255 to 0 - transition to green

-Add another for loop here for red. You should be getting the idea...

//Vary blue from 0 to 255 - transition to aqua

//Vary red from 0 to 255 - transition to white

//Vary green from 255 to 0 - transition to violet

//Vary red from 255 to 0 - transition to blue

//Vary blue from 255 to 0 - transition to black

//Repeat

Explanation / Answer

//RGB LED
//The RGB LED will appear red, yellow,green,aqua,white,voilet,blue,black
/*************************************************************************/

const int redPin = 11; // R petal on RGB LED module connected to digital pin 11

const int greenPin = 10; // G petal on RGB LED module connected to digital pin 9
const int bluePin = 9; // B petal on RGB LED module connected to digital pin 10
/**************************************************************************/

void setup()
{
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
}
/***************************************************************************/
void loop() // run over and over again

int r, g, b;

r=0;

g=0;

b=0;

// turn the RGB LED red  

for (r = 0; r < 256; r++){

color(r, g, b);

}

// turn the RGB LED Yellow

for (g = 0; g < 216; g++){

color(r, g, b);

}

// turn the RGB LED Green

for (g = 216; g < 256; g++){

color(r, g, b);

}

// turn the RGB LED

for (r = 255; r.<1; r--){

g=255;

color(r, g, b);

}

// turn the RGB LED Aqua

for (b = 0; b < 256; b++){

color(r, g, b);

}

// turn the RGB LED White

for (r = 0; r < 256; r++){

color(r, g, b);

}

// turn the RGB LED Voilet

for (g = 255; g < 1; g--){

color(r, g, b);

}

// turn the RGB LED Blue

for (r = 255; r < 1; r--){

color(r, g, b);

}

// turn the RGB LED Black

for (b = 255; b < 1; b--){

color(r, g, b);

}

}
/******************************************************/
void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
{
analogWrite(redPin, red);
analogWrite(bluePin, blue);
analogWrite(greenPin, green);

delay(10);
}
/******************************************************/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote